function custom_category_blog_filter( $query ) { // Check if this is the main query and not an admin page, and if it's a category page if ( $query->is_main_query() && !is_admin() && is_category() ) { // Get the current category ID and filter posts based on that $category = get_queried_object(); if ( $category ) { $query->set( 'cat', $category->term_id ); // Use term_id instead of get_queried_object_id() } } } add_action( 'pre_get_posts', 'custom_category_blog_filter' );
Open chat
Have any questions?
Hi there!
Is there anything you need help with?
Pop me a message and I'll get back to you.