I need to get_pages or get an array of pages in WP based on it ‘s category
I know WP doesn’t come with categories on pages but I’m using this in the functions.php to get categories on the pages.
add_action('admin_init', 'reg_tax');
function reg_tax() {
register_taxonomy_for_object_type('category', 'page');
add_post_type_support('page', 'category');
}
Now I need to use these categories in get_pages or WP_Query to get in the pages with a category.
<div class="productNav">
<ul>
<?php
$product_page_args = array(
'post_type' => 'page',
'order' => 'ASC',
'orderby' => 'menu_order',
'child_of' => $post->ID,
'category_name' => 'pillar-product'
);
//$product_pages = get_pages($product_page_args);
$product_pages = new WP_Query($product_page_args);
foreach ($product_pages as $product_page){
?>
<li><?php echo $product_page->post_title; ?></li>
<?php
}
?>
</ul>
</div>
Try this: (won’t work on wordpress
5.8
)For more comprehensive answer on how to query wordpress pages based on specific category see the following link:
Here’s the correct answer for this question, fully tested on wordpress
5.8
.