My custom post type is set to “public => false” for reasons, but now I can’t select the post type in ACF Location Rules. Is there a setting I missed?
Check the “Show in UI” settings under the advanced settings.
Thanks. It works for my custom post type
Strangly, it doesn’t work with the WP ‘post’ post type.
I changed the arguments as follow, but ‘Post’ is not visible in ACF Location Rules.
function change_post_type_args( $args, $post_type ) {
if ( $post_type !== 'post' ) { return $args; }
$args['public'] = false;
$args['show_ui'] = true;
return $args;
}
add_filter( 'register_post_type_args', 'change_post_type_args', 10, 2 );
I just had a look through the code in ACF and here is the issue
FILE: includes/api/api-helpers.php
function acf_get_post_types()
LINE: ~642
// Bail early if is builtin (WP) private post type
// i.e. nav_menu_item, revision, customize_changeset, etc.
if ( $object->_builtin && ! $object->public ) {
continue;
}
There is a filter
return apply_filters( 'acf/get_post_types', $post_types, $args );
and you could use this filter to add ‘post’ back in.
Can you show me how to apply the filter code correctly? I’m lost. Thanks.
add_filter('acf/get_post_types', 'include_private_post_types', 20, 2);
include_private_post_types($post_types, $args) {
if (!in_array('post', $post_types)) {
$post_types[] = 'post';
}
return $post_types;
}
Thanks. That worked for me. (added missing ‘function’)
add_filter('acf/get_post_types', 'include_private_post_types', 20, 2);
function include_private_post_types($post_types, $args) {
if (!in_array('post', $post_types)) {
$post_types[] = 'post';
}
return $post_types;
}
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.