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.
FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.
FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.
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.
Tags:
Aileen Javier Aileen has over 10 years of experience in content writing and content marketing. She’s handled content teams, planned editorial calendars, and managed projects. She’s also written blogs, web copy, social media posts, and email newsletters for brands in different industries.