# 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](https://github.com/Hube2/acf-dynamic-ajax-select-example).
## Important Note
ACF In constantly changing. It is possible that any of the examples here may stop working with an update to ACF. I do not actively maintian these examples or continuously monitor them to make sure they are working. This repository was created to hold examples of some things that may help other. If you find that something is not working as expected you can open an issue, however, unless I have the free time the chances of me fixing the issue are small. This is why I will gladly take pull request for fixing problems with compatibility.
#### 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.
##### [acf-custom-post-type-filters.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-custom-post-type-filters.php)
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.
##### [acf-delete-images-when-removed-from-gallery.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-delete-images-when-removed-from-gallery.php)
This is an example of how to delete images from the media library when they are removed from a gallery field
##### [acf-extended-admin-columns.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-extended-admin-columns.php)
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.
##### [acf-field-label-functions.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-field-label-functions.php)
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.
##### [acf-form-kses.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-form-kses.php)
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.
##### [acf-image-aspect-ratio-validation.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-image-aspect-ratio-validation.php)
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.
##### [acf-load-parent-theme-field-groups.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-load-parent-theme-field-groups.php)
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.
##### [acf-options-page-w-cpt-children.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-options-page-w-cpt-children.php)
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.
##### [acf-page-ancestor-location-rule.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-page-ancestor-location-rule.php)
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.
##### [acf-page-granparent-location-rule.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-page-granparent-location-rule.php)
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.
##### [acf-post-category-ancestor-location-rule.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-post-category-ancestor-location-rule.php)
This is another custom location rule example. This one sets a location based on category ancestor. It will
actually work with any hierarchical taxonomy.
##### [acf-reciprocal-relationship.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-reciprocal-relationship.php)
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.
##### [acf-reciprocal-relationships-multiple.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-reciprocal-relationships-multiple.php)
Contributed By: [PUncle](https://github.com/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+.
##### [customized-options-page.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/customized-options-page.php)
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.
##### [change-option-page-location-display.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/change-option-page-location-display.php)
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-mouse-scrollwheel-action.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/correct-number-field-mouse-scrollwheel-action.php)
Correct number field scrollwheel behavior
##### [default-image-for-image-field.php](https://github.com/Hube2/acf-filters-and-functions/blob/master/default-image-for-image-field.php)
This is a simple examp
没有合适的资源?快使用搜索试试~ 我知道了~
用于高级自定义字段 WP 插件的 通用过滤器和功能_PHP_代码_相关文件_下载
共26个文件
php:24个
md:1个
png:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2022-07-12
21:59:30
上传
评论
收藏 48KB ZIP 举报
温馨提示
ACF 过滤器和功能 用于高级自定义字段 WP 插件的通用过滤器和功能 有关如何基于其他字段选择创建动态加载字段的示例,例如基于在另一个选择字段中所做的选择动态加载选择字段,请参见我的其他示例。 重要的提示 ACF 在不断变化。此处的任何示例都可能因 ACF 更新而停止工作。我不会主动维护这些示例或持续监视它们以确保它们正常工作。创建此存储库是为了保存一些可能对其他人有所帮助的示例。如果您发现某些事情没有按预期工作,您可以打开一个问题,但是,除非我有空闲时间,否则我解决问题的机会很小。这就是为什么我很乐意接受拉取请求来解决兼容性问题。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
acf-filters-and-functions-master.zip (26个子文件)
acf-filters-and-functions-master
acf-json-save-based-on-group-key.php 3KB
acf-page-ancestor-location-rule.php 2KB
default-image-for-image-field.php 525B
is_admin-acf-location-rule.php 1KB
correct-number-field-mouse-scrollwheel-action.php 2KB
customized-options-page.php 3KB
acf-extended-admin-columns.php 2KB
acf-custom-post-type-filters.php 2KB
acf-load-parent-theme-field-groups.php 2KB
render-image-in-editor.php 1KB
acf-form-kses.php 2KB
unique-repeater-sub-field.php 2KB
acf-page-granparent-location-rule.php 2KB
acf-reciprocal-relationships-multiple.php 7KB
Untitled-1.png 24KB
change-option-page-location-display.php 548B
acf-field-label-functions.php 4KB
acf-delete-images-when-removed-from-gallery.php 780B
public-post-type-location-rule.php 1KB
acf-post-category-ancestor-location-rule.php 2KB
README.md 10KB
acf-options-page-w-cpt-children.php 3KB
acf-reciprocal-relationship.php 6KB
acf-image-aspect-ratio-validation.php 4KB
page-nth-level-location-rule.php 2KB
public-taxonomy-location-rule.php 1004B
共 26 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功