pre_get_posts // category
-
from our sidebar, using the category widget, I’d like to navigate to a page showing all posts in that particular category (10 posts per page)
does anyone know where I could find code snippets to input in my functions file for this?
I found this code but I want category, not archive – when I just changed that word, this code didn’t work and I can’t seem to find the right phrasing online
add_action( 'pre_get_posts', 'custom_post_type_archive' ); function custom_post_type_archive( $query ) { if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) { $query->set( 'posts_per_page', '6' ); $query->set( 'orderby', 'title' ); $query->set( 'order', 'DESC' ); } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘pre_get_posts // category’ is closed to new replies.