Skip to main content
1 of 2
Shazzad
  • 3.3k
  • 1
  • 17
  • 23

You need to use pre_get_posts hook. Where u can include the default category posts on other category pages.

function wpse_pre_get_posts( $q )
{
    // its the main query, and its the category page archive
    if( $q->is_main_query() && $q->is_category() ) :

        // get the default selected category id, fallback to 1 (default one id)
        $default_cat = (int) get_option('default_category', 1);

        // if the category page is not the default category page
        if( $default_cat != $q->get_queried_object_id() ):

            // get the already used tax_query arguments
            $tax_query = $q->get('tax_query');

            // add the default one
            $tax_query[] = array(
                'taxonomy' => 'category', 
                'field'    => 'term_id', 
                'terms'    => $default_cat 
            );

            // relation should be or, which means either the current category or the default
            $tax_query['relation'] = 'OR';

            // set the values to query
            $q->set('tax_query', $tax_query );

        endif;

    endif;
}
add_action( 'pre_get_posts', 'wpse_pre_get_posts' );

That's it. You are all done

Shazzad
  • 3.3k
  • 1
  • 17
  • 23