0

I created category function by adding this code to functions.php:

function page_category() {  
register_taxonomy_for_object_type('category', 'page');  
}
 // Add to the admin_init hook of your theme functions.php file 
add_action( 'init', 'page_category' );

But the thing is that when I go to a category page, the page does not show the pages that are in the category. I read it is because categories are meant to show only posts.

Is there any way show pages in categories, without using a plugin?

Thanks!

1 Answer 1

2

Have you try:

function my_custom_show_pages_in_category( $query ){
     if( $query->is_category() && $query->is_main_query() ){
           $query->set('post_type', array('post', 'page' ) ) ;
     }
}
add_action('pre_get_posts', 'my_custom_show_pages_in_category' );

See more: Codex

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.