admin管理员组文章数量:1130349
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',
)
)
);
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',
)
)
);
本文标签: Display all page which have not a certain template
版权声明:本文标题:Display all page which have not a certain template 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749040510a2307060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论