Support

Account

Home Forums Backend Issues (wp-admin) How can I dynamically filter the list of posts? Reply To: How can I dynamically filter the list of posts?

  • Thanks!

    Making some headway, here is my new test code:

    function my_post_object_query( $args, $field, $post )
    {
    	
    	$args['cat'] = wp_get_post_categories($post->ID);
    	echo '<pre>';
    	print_r($args);
    	echo '</pre>';
    	//die;
        return $args;
    }
    
    // filter for a specific field based on it's key
    add_filter('acf/fields/post_object/query/key=field_524f02159316d', 'my_post_object_query', 10, 3);

    This returns the following array:

    Array
    (
        [numberposts] => -1
        [post_type] => post_images
        [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
        [cat] => Array
            (
                [0] => 5
            )
    
    )

    you can see the cat id is getting added, but the results that come back in the dropdown are not filter to only include posts form catid 5