Home Forums Backend Issues (wp-admin) Post Object: Query by page-template issue?


Post Object: Query by page-template issue?

  • Hi everyone,

    I encounter a problem when I want to filter the results in the back office.
    Here is my example, I have parent and child pages:
    – Page 1
    — Subpage 1-1 (Template “Book”)
    — Subpage 1-2 (Template “Book”)
    – Page 2
    — Subpage 2-1 (Template “Book”)
    — Subpage 2-2 (Template “Book”)
    – Page 3 (Template “Book”)

    And here is my code:

    function my_post_object_query($args, $field, $post_id) {
        $args =  array(
    			'post_type'   => 'page',
    			'meta_query'  => array(
    				'relation'  => 'AND',
    					'key'     => '_wp_page_template',
    					'value'   => 'templates/book.php',
    					'compare' => '='
        return $args;
    add_filter('acf/fields/post_object/query/name=book_obj', 'my_post_object_query', 10, 3);

    I have in my results only “Page 3”, basically, no “child pages” are displayed.
    Do you know why?

    EDIT: If I add “post_parent” with the ID of a parent page it works, but I do not want to put IDs hard… Is this a plugin bug?

  • I come to give the solution for people who have the same problem.
    I was coming to overwrite the arguments instead of adding them to the array.

    It is necessary to do as follows:
    $args['my_parameter'] = 'my_value';

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

You must be logged in to reply to this topic.