Home Forums Backend Issues (wp-admin) post_object/query exclude page (4.4.11)


post_object/query exclude page (4.4.11)

  • I’m trying to exclude a ‘page’ via post_object/query with the following filter but although any ‘post’ or ‘custom post type’ can be excluded from the dropdown list, I can not exclude any ‘pages’ via their IDs.

    add_filter(‘acf/fields/post_object/query’, ‘my_post_object_query’, 10, 3);
    function my_post_object_query( $args, $field, $post_id ) {

    $args[‘post__not_in’] = array( 575 ); // 575 is id of page to exclude

    return $args;


    Is it possible to exclude a ‘page’ and if so, please can you help?


  • Hi @ianhempsell

    I’ve just tested the code on my installation and it’s working great. Maybe there’s something on your site that modifies the query. Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    Thanks 🙂

  • Hi James,
    Thanks for the quick response. However, I have created a brand new installation of Twentyseventeen and tested with the default post and page with no other plugins installed and I get the same issue.

    In this situation, I have added a Field Group to POSTS with a single Post Object field:

    Post Object Field Screengrab

    In my functions file, I have the following filter to exclude the Sample Page with an ID of 2:

    Functions File Filter

    But when I select the Field on a post, you can see that the Sample Page is still available for selection:

    Post Object Dropdown on POST admin screen

    What am I doing wrong?

    Appreciate your help and have a great Christmas ;o)

  • Hi @ianhempsell

    For the pages, you should use the “exclude” option instead. So it should be like this:

    add_filter('acf/fields/post_object/query', 'my_post_object_query', 10, 3);
    function my_post_object_query( $args, $field, $post_id ) {
        $args['exclude'] = "2,99"; // 2 and 99 are IDs of pages to exclude
        return $args;

    I hope this helps 🙂

  • Thanks for the help James, ‘exclude’ has resolved my issue.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘post_object/query exclude page (4.4.11)’ is closed to new replies.