Skip to content

General filters and function for use with Advanced Custom Fields WP Plugin

Notifications You must be signed in to change notification settings

psntr/acf-filters-and-functions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ACF Filters & Functions

General filters and function for use with Advanced Custom Fields WP Plugin

For examples of how to create dynamic loading fields based on other field selections, for example dynamically loading a select field based on a selection made in another select field see my other examples here.

Contributing

If you would like to contribute to these examples, create a pull request with a new file and update the list below. I would like to avoid changing any of the existing examples in this repo unless the changes are to resolve bugs or to deal with any changes to ACF that cause the original examples to stop functioning.

File/Example List

File names basically tell you what the code does. See comments in individual files for more information.

Since this repo has started to grow, here is a list of what you'll find in the files.

This is a file that gives an example of creating custom location rules to match the posts in a custom post type similar to Post and Page.

This is an example of how to delete images from the media library when they are removed from a gallery field

This is an example of how to extend the ACF admin columns to show additional information. This example adds the menu order and the location rules for each group to the admin.

This is a group of custom functions for returning the labels of fields as well as the labels for choices in choice fields like radio, select and checkbox fields.

This file has a function for applying safely wp_kses_post() to all ACF fields. You can't apply this to repeaters and flexible content fields becuase these fields contain array values and the function deletes these arrays. This filter can also be used as an example of recursively applying any function to ACF fields and arrays in general.

Add image aspect ratio validation to image fields. Also an example of how to add multiple setting fields to a single setting row for an acf field type setting.

This file contains small class that will conditionally load ACF field groups from a theme parent. You add this to your parent theme. It looks at the files in the parent themes acf-json folder and if a field group in this folder does not already exist then it is loaded.

This is useful because it lets you work on the field groups in your development environment without needing to delete those field groups. When an update is applied to your parent theme any changes you've made to the field groups will be automatically applied to child themes.

Just as as side note, I also use this process when developming plugins, with a few modifications. It lets me keep a working copy of my plugin that uses ACF field groups that I edit using ACF. I can then copy the changes from tha theme folder to my plugin and the changes will be applied when the plugin is updated on a site.

This is an example of how to add a custom post type as a sub menu item to an ACF Options Page. The last I checked this cannot be done because ACF uses a priority > 9 for the admin_menu hook. For more information see the comment at the top of the file.

This is another custom location rule example. This custom location rule lets you choose to set a field group to be located on any page that is a descendant of the page selected.

This is another custom location rule example and it is similar to the ancestor location rule except that the field group will only be located on pages that have a particular grand parent, or the second ancestor.

This is another custom location rule example. This one sets a location based on category ancestor. It will actually work with any hierarchical taxonomy.

This file contains and example of how to create a reciprical or two way relationship field using either 1 or 2 relationship or post object fields. This file must be edited to match the field or fields that you wish to convert into a bidirectional relationship. See the comments in the file for more information.

Contributed By: PUncle

Like the acf-reciprocal-relationship.php example above, this function allows two different reltionship fields to reciprocate selections. The difference being that this function usues PHP closures to pass in field keys, avoiding the need to hard-code them inside the function; making this example reusable across multiple reciprocal relationships. This function requires PHP 5.3+.

This is an example of how you can make modification to an ACF Options Page to add additional content into the page that is generated by ACF, for example between the title and the ACF field groups.

ACF shows the menu_title as the choice in location rules. This can be confusing for those of use that create multiple options pages with the same menu title and different page titles. This filter alters the location display to show the page title instead.

Correct number field scrollwheel behavior

This is a simple example of how to add a default image setting to image fields. Note that this is only a bisic example and may require you to save the field group before you can select a default image. I have posted more information here on how to correct this situation

This is another custom location rule example. This rule lets you choose a field group to be used only in the in the admin or on a front end form.

This is another custom location rule example. This rule let's you choose to display a field group only on a specific level of a hierarchical post type. This rule should work with any hierarchical post type.

This is another custom location rule example. This one will let you choose a location based on whether or not the post type is a public post type.

This is like the public post type rule, but for taxonomies

This is an example or how to render additional information in a field. This particular example shows how to display an image when the URL for the image is from another site rather than an image in the media library.

A filter that can be used to check for unique repeater sub field values in any repeater.

About

General filters and function for use with Advanced Custom Fields WP Plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%