Home › Forums › Feature Requests › New feature for posts with post_parent=0
I have a custom post type where each post has children under it (like pages do).
I was just making some fields and i came accross the following needs:
– post object: It would be handy if we could set to show only the ones with post_parent=0. So i would like to be able to fetch only the “main” posts for a custom field with type: post object.
– when you set a new Field group: In the Location -> Rules it would be nice to be able to set this group only for posts with post_parent=0 or for posts with post_parent>0
thanks! Great plugin
The first part can be done using this filter https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/
The second part requires creating a custom location rule https://www.advancedcustomfields.com/resources/custom-location-rules/. I have some example custom location rules here https://github.com/Hube2/acf-filters-and-functions. There’s not one that is specifically for what you want. If you dig around in ACF and find the page type location rules you can pretty much copy most of what you need from ACF for use with your custom post type. Although, I just dug around in ACF and it seems that the Page Type location rule should work for parent/child no matter what post type you use it on (unless I’m missing something)
Thanks for the quick reply!
The first part is now solved with the filter you mentioned.
For the second part, the page parent will only return a list of my pages. If it also returned the ‘0’ value then i could use this. I will check the links you sent and see what i can manage.
Still it would be nice to also have a post parent in the location rules or also include the ‘0’ in page parent.
This does not work?
is equal to
Parent Page (has children)
I already know that it’s not likely that custom location rules will be added for custom post types, at least not by the developer. So it the above does not work your only real option is to create a custom location rule.
And I do have an example that will do something similar here https://github.com/Hube2/acf-filters-and-functions/blob/master/page-nth-level-location-rule.php that I’m sure can be made to work with a few tweaks.
I hadn’t noticed that “page type” has these options.
this solved it.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.