Hey hey, I’m trying to wrap my head around customizing post_object select fields. (reference: http://www.advancedcustomfields.com/resources/filters/acf-fields-post_object-query/)
I’ve added this code to functions.php but it doesn’t seem to have any effect on the way posts are displayed in the select field. Instead, the standard select field with all post objects are being displayed. I only want it to display children of the current post. What am I doing wrong?
function my_post_object_query( $args, $field, $post )
{
global $post;
// only show children of the current post id
$args['post_parent '] = $post->ID;
return $args;
}
// filter for a specific field based on it's name
add_filter('acf/fields/post_object/query/name=my_post_field', 'my_post_object_query', 10, 3);
Hi @nc
Can you please debug the args like so and report the findings.
<?php
echo '<pre>';
print_r( $args );
echo '</pre>';
die;
?>
This code would be place before the return
Thanks
E
Oops, didn’t see your reply til now. Thanks! This still isn’t resolved yet.
Okay, this is what I get:
Array
(
[numberposts] => -1
[post_type] => custom_type
[orderby] => title
[order] => ASC
[post_status] => Array
(
[0] => publish
[1] => private
[2] => draft
[3] => inherit
[4] => future
)
[suppress_filters] =>
[sort_column] => menu_order, post_title
[sort_order] => ASC
[post_parent ] => 695
)