Don’t use query_posts()
use the WP_Query
class instead… the link to the Codex will also reference all the appropriate query parameters.
The following would query the most recent post in a particular category, you will need to define the $category_id
// The Query
$query = new WP_Query( 'cat' => $category_id, 'posts_per_page' => 1 );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
get_template_part( 'content-category', get_post_format() );
}
}
/* Restore original Post Data */
wp_reset_postdata();
Related Posts:
- Could not insert term into the database
- Activate Gutenberg in category-descriptions
- How can I get category ID by category name?
- How would I increase the Author Role to be able to add a new category?
- How to remove the parentheses from the category widget
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Only show category to certain user levels without plugin
- How to: 301 Redirect /category/ to /customname/
- Custom Query to search through categories
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Get sticky post from category?
- Display one latest post from multiple categories
- Remove word “Category” from WooCommerce product page [closed]
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- How Do I Merge Categories With phpMyAdmin
- Display name of the last child category
- Edit the markup of categories list
- Show category children, one level
- If in category to be inside of a function
- How to exclude posts from a category when using this particular format
- Viewing category pages without the word ‘category’ in URL
- How to view WordPress’ default category IDs?
- Random taxonomy category list
- how to change template?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Product Category WooCommerce
- Show all posts for a specific category/author
- Hard coded main navigation
- Resort get_categories
- Display posts separated by Category in Author’s page
- How can I define a custom archive for childs of a specific category?
- The arrangement of categories always change while posting article
- Woocommerce custom category page with pagination [closed]
- List posts in alphabetical order
- Categories list loop – add separator every 3 categories [closed]
- wp_list_pages() exclude category
- Limit categories and it’s subcategories for specific group of users
- Get the ID of 10 Latest Pages stored in a WordPress Category
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- getting post data in functions.php
- Category specific order
- How can i remove the posts category class names from body_class
- Different Category Headers using in_category and elseif
- Remove the number of posts displayed in wp_list_categories()
- related articles using shortcodes
- “Virtual category page” based on a custom field filter
- Show category meta in loop on homepage
- How to get selected taxonomy or category ID if using custom walker?
- Category link redirect to custom template page instead of index.php?
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- Get categories related to particular category
- the_category() doesn’t working in wp_query loop
- Displaying links to all posts of the same category on the post page
- handling the featured category
- Add class to current post in query_post
- separate posts to have (kind of) 2 blogs?
- create relationship between posts from one category and posts from another category
- Exclude the category of the current post
- Sort posts by child category name
- Intermittent Gutenberg 504 Gateway Timeout when calling REST route to retrieve categories
- display specific category when website loads
- Excluding current category from sidebar’s post widget, elementor, query-id
- OK to redirect the root WordPress category slug?
- Show subChild categories
- WooCommerce REST API not returning the default products category
- Displaying data from custom fields on a specific category page
- Get WooCommerce product category list in functions.php
- Include a page’s “category” in its URL
- Excluding specific category from custom theme functions
- Using the slug of a custom post category as prefix for the underlying custom post slugs
- Change background image page header overlay for each category
- List non-empty categories from a custom post type
- Creating a linkable category list with post count
- Displaying portions of multiple pages from a given category, in a single summary page
- Change wp_link_pages to link to another page
- Hide post category name wherever it might be mentioned
- Issue with WordPress category search
- WordPress Category url redirects to subdomain
- get_the_terms_list output last child only
- Exclude posts with certain tags in category archive
- Loop doesn’t work
- How to loop through a custom field for each post, & display?
- How to add additional field to Add new category part (without plugin use) [closed]
- show category name before first posts in each category
- Need list of child category post titles sorted by child category
- Lowest catagory link
- Category and tags goes 404
- Wrong category being displayed in URL
- Displaying posts from a Category where the Category ID or slug is not known
- Custom CSS to resize elements in multiple categories
- Custom built theme won’t filter categories
- Way to show content of a post, but if exceeds character limit revert to excerpt?
- get IDs from links categories
- Display all subcategories for a product category in woocommerce
- Why does my WordPress index has a category?
- Function to reference post meta in place of category Woocommerce
- hide_empty property not working when using get_terms
- Category Redirection Problem
- Hierarchical outline of posts