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
- How to get URL of current page displayed?
- What does the token %1$s in WordPress represent [closed]
- exclude multiple terms using get_terms() function
- Display list of Sub-Categories and the posts they contain, within one main Category
- Display only text to WordPress loop without loosing the text formatting
- Display all posts in current category
- How to display related posts from parent category
- How can I set custom order use this function
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- Check if Product is in a Specific Category in Functions.php
- Way to display “Yesterday”, “Today”
- multiple if statements [closed]
- have_posts() execution failure
- Category Thumbnail Display – How to display ONLY the main Category
- How does the ternary operator work in the wordpress loop post?
- Swapping wp_dropdown_categories function with wp_category_checklist
- Cannot display or echo alt text on featured image
- Show full posts in archive
- Using loop pagination on single.php
- How to set variable, pass it to a partial file and remove it after?
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Can’t find infinite loop cause
- how to show only specific category for a template
- Changing the_posts_navigation() html output
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- Loop stopped working
- How to loop through all the attached images in a post, and get their url one by one
- Store post content in a php variable and output them using for loop
- Displaying posts based on category
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WooCommerce: Display product categories to make IF statement
- Trying To Get Child Categories To Show, Issue With foreach Loop
- Have posts that belong to multiple categories, exclude some categories from homepage
- Echo array value
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- How to break up php code to avoid echo
- Add Custom Category Description When Empty
- Add a product category to a specific product via a button
- Products listing check if meta checkbox is checked
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- Get title of page containing post grid within the posts
- How to Link to category titles if it is in the single post content?
- How can i show specific Category List?
- How to show category just on specific pages?
- How to filter specific element of an array in wordpress/php?
- How can I get my pagination loop to display the correct number of total pages?
- How do if all posts has this category ID then do this
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- View tag description on page
- Displaying Category in sidebar post widget but not in the loop on home
- List categories assigned to a post
- Insert div after every three posts in home.php [duplicate]
- Unable to get Post Category Name and URL
- Display product attributes for current product
- Trying to see if page is category or single and displaying title with appropriate heading tag
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- Transient Loop Not working as expected
- 2 loops in archive.php (one for each category)
- How to change links in the 3 main categories, on widget category, to a javascript function call
- how to set category name for a post
- Conditional in foreach loop is outputting content twice
- is there away to hide php code in wordpress not to show in PAGES
- Custom archives page by month and year – nesting problem
- How to create categories out of a list of words?
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress