Before you mark this as duplicate I have tried every method in all the other questions and non of them have worked.
I am trying to exclude any page with the page template page-noindex.php from the wp_list_pages(); query.
The below code does not work and when I echo out $the_query it just displays 'Array'.
<?php
$the_query = array(
'post_type' => 'page', /* overrides default 'post' */
'meta_key' => '_wp_page_template',
'meta_value' => 'page-templates/page-noindex.php'
);
$args = array(
'exclude' => $the_query,
'title_li' => '',
'sort_column' => 'menu_order, post_title',
'post_type' => 'page',
'post_status' => 'publish'
); ?>
<?php wp_list_pages($args) ?>
Before you mark this as duplicate I have tried every method in all the other questions and non of them have worked.
I am trying to exclude any page with the page template page-noindex.php from the wp_list_pages(); query.
The below code does not work and when I echo out $the_query it just displays 'Array'.
<?php
$the_query = array(
'post_type' => 'page', /* overrides default 'post' */
'meta_key' => '_wp_page_template',
'meta_value' => 'page-templates/page-noindex.php'
);
$args = array(
'exclude' => $the_query,
'title_li' => '',
'sort_column' => 'menu_order, post_title',
'post_type' => 'page',
'post_status' => 'publish'
); ?>
<?php wp_list_pages($args) ?>
Share
Improve this question
asked Aug 21, 2017 at 20:56
Daniel VickersDaniel Vickers
1185 bronze badges
1
|
1 Answer
Reset to default 1Daniel, exclude
parameter doesn't accept array.
Use your code this way:
$exclude = [];
foreach(get_pages(['meta_key' => '_wp_page_template', 'meta_value' => 'page-templates/page-noindex.php']) as $page) {
$exclude[] = $page->post_id;
}
$args = array(
'exclude' => implode(",", $exclude),
'title_li' => '',
'sort_column' => 'menu_order, post_title',
'post_type' => 'page',
'post_status' => 'publish'
);
wp_list_pages($args);
I think you can refactor it better for your needs
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745554717a4632749.html
print_r($the_query)
instead. – Johansson Commented Aug 21, 2017 at 21:08