You can add category id
or category slug
into arguments you are passing to query_posts
:
<?php
// category slug ('products')
query_posts(array(
'post_type' => 'post',
'showposts' => 5,
'category_name' => 'products'
) );
?>
or
<?php
// category id ('3')
query_posts(array(
'post_type' => 'post',
'showposts' => 5,
'cat' => '3'
) );
?>
In the second case you can use comma separated list of category ids like 'cat' => '3,5,7'
.
Related Posts:
- Exclude category and post from loop in custom category.php
- Inject post (from specific category) between posts in Loop
- Archive listing of posts by publish year (multiple years)
- Alter secondary loop to exclude posts from current page category
- User Defined order on get_categories?
- Custom Loop through category menu to include sub categories
- How to exclude specific category from the get_the_category(); array
- Filter Select results based on selection
- What is an equivalent of single_cat_title for getting the slug of the category?
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- How to get the last category name of a child category?
- Issue with custom loop in Archive page
- How to get current post category details inside “loop”?
- Problem with custom loop and wp_list_pluck [closed]
- Echoing a CSS class based on category of post in a list
- Do not duplicate posts with multiple categories in multiple loops
- How to Fix an Archive.php That Displays All Posts?
- First post article different on Archives template
- Woocommerce. Get a list of products in the current category on the archive page and product page
- Link to index.php from home.php?
- Return to the beginning of the results of a for loop
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Error trying import one category on page
- dynamically filter by category via sub-menu
- Remove the_content From Loop
- Hide empty categories from get_categories
- WordPress categories not working throughout site
- Exclude a category ID from the following function
- Changing layout with wp_customise
- Proper syntax or method for keeping url in modified isotope / category links
- Display post category in foreach loop with category link
- Show full posts in archive
- Dynamic Stylesheet loads but doesn’t finish
- Getting the author name on author archive page
- Second level subcategory
- Using loop pagination on single.php
- Query Posts Exclude Entire Category
- Loop with slider (slider not loading)
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Issue adding sub category programmatically
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- how do I get a specific post from a post with a subcategory in WP
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- How do I exclude recent post from recent post php widget
- Move category description below post list in blog
- How to pick the default selected value in wordpress dropdown?
- Iterate through posts based on array of categories
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- get author_name from queried post
- Displaying Woocommerce Product Category in WordPress
- How can I add extra word in permalink when someone click download button?
- Increase offset while looping
- selected option if current category is the value
- Blog posts repeat
- How to add condition in wordpress loop? [closed]
- Woocommerce : Can’t get product info in loop
- get_template_part based upon post’s category
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Hide subcategories (widget)
- Counter in loop in foreach
- Let Users Choose Post Categories
- remove post that has no content
- Different post styles depending on category
- Can’t find infinite loop cause
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- wordpress archive a user
- Load wordpress content in other domain
- How to show only subcategories in parent category not parent category?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Checkbox doesn’t stay checked, conten
- how to show only specific category for a template
- post thumbnail, conditions, else wont work
- Widgets in the loop if active
- List posts that don’t have a specific tag?
- Changing the_posts_navigation() html output
- Dilemma of Populating all the categories in a drop down list
- Can we count the WordPress Loop
- Display most popular posts of category
- Get post id within comments loop
- Syntax error when I try to insert my loop into an unordered list? [closed]
- WP_Query fails despite having 1 post
- Creating sub-categories via php
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- JSON REST API WordPress only showing first 10 categories