How to Show Only One Category on Your WordPress Homepage

If you’d like to show posts from only one category on your homepage, then it’s easy enough to do.

We’ll go over the steps below.



Find Your Category ID

First find the category ID number of the category you want to show up. You can do this by mousing over the category title (Posts > Categories), and then look in the bottom of your browser. You should see the category ID among a string of other messy info.

In this example, the category is 11.


You can also use a plugin that will give you different IDs in your Admin area.


Insert Code

Once you have your category ID, put that into the following code, which should go into your functions file. (Appearances > Editor > Theme Functions – functions.php)

As you’ll be changing your theme’s function file, it would be wise to use a child theme.

In the example code below, I’m using category ID number 11. Replace that with your category ID.

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' );

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’ );

And that’s all there is to it. You should now only see posts on your homepage from the category you singled out in your code.


Comments (11)

  1. I have applied this code,

    /**Edited Nov-27-2014 – Page to Category**/
    /** Bayan News (Page) – to – Category (Bayan News) **/
    function Bayan_News_category( $query ) {
    if ( $query->bayan-news() && $query->is_main_query() ) {
    $query->set( ‘cat’, ‘5’);
    add_action( ‘pre_get_posts’, ‘Bayan_News_category’ );

    and my site gets HTTP 550 Internal Server Error.

    Whats wrong and where to apply it. I am using u-design theme.

  2. Wrathy_imp and all others who try to use the second snippet above:

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

    Note that the second set of arguments ‘11,14’ have smart quotes around them — for some reason the snippet introduced smart single quote

    rather than a

    there is a HUGE difference and php parser barfs on it. Please use the snippet

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

    Note the similar formatting (however slight) on the first and second set of arguments…

    Wrathy_imp look for the line

    $query->set( ‘cat’, ‘5’);

    Make sure the ‘5’ is using regular straight quotes.

    Unfortunately your editor for themes may not be accessible now so you may have to edit this in the ssh shell or through FTP.

    Wouldn’t it be nice for the theme editor to restrict characters like this from being submitted? :)