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' => '!=',
)
)
);
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' => '!=',
)
)
);
Share
Improve this question
edited Jan 5, 2019 at 22:49
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Jan 5, 2019 at 22:40
QuentinQuentin
158 bronze badges
1 Answer
Reset to default 0You 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',
)
)
);