• Resolved troxx

    (@troxx)


    Hello, I have an issue… I have about 30 categories on my site, I’ve excluded all of them from the homepage (using plugins like Ultimate Category Excluder ) – all but one (it’s a “news” category). But sometimes, my client wants to have post from a different category to be shown on the homepage. I’ve tried to put one post into two categories – logical, isn’t it? But it doesn’t work with such plugins ?? If a post is ONLY in the “news ” category – it shows on the home page. If its in the “news” and “other” category – it doesn’t show on the homepage. Can you help somehow? I’ve tried various plugins for excluding categories from the homepage, but all of them work the same way.

Viewing 1 replies (of 1 total)
  • Thread Starter troxx

    (@troxx)

    Ok, I’ve resolve the issue by adding the following code do the funcions.php file:

    function my_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '11'); } } add_action( 'pre_get_posts', 'my_home_category' );

    note that you should put your wanted cat id in the

    set( 'cat', '11');

    part.

    If you would like to include more than one category, then just add another ID by inserting a comma and the ID number. For example, this is will display category 11 and category 14.

    $query->set( 'cat', ’11, 14’ );

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple post categories and only one on the homepage…’ is closed to new replies.