0

I'm trying to display all pages of my website which have not the following template: template-rubrique.php.
It works great but it doesn't output the blog page as well, since it doesn't have a template at all.

How should I proceed?

$args = array(
  'post_type'      => 'page',
  'posts_per_page' => -1,
  'order'          => 'ASC',
  'orderby'        => 'title',
  'meta_query'     => array(
    array(
      'key'       => '_wp_page_template',
      'value'     => 'template-rubrique.php',
      'compare'   => '!=',
    )
  )
);

1 Answer 1

0

You can add an OR relation to the meta query and also get pages with no _wp_page_template meta key:

$args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
    'order'  => 'ASC',
    'orderby' => 'title',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => '_wp_page_template',
            'value' => 'template-rubrique.php',
            'compare' => '!=',
        ),
        array(
            'key' => '_wp_page_template',
            'compare' => 'NOT EXISTS',
        )

    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.