The following code will query the “blog” category for the latest three published posts and loop through these results to display the excerpt from each.
$args = array(
'category_name' => 'blog',
'post_status' => 'publish',
'posts_per_page' => 3,
);
$blog_posts = new WP_Query( $args );
if ( $blog_posts->have_posts() ):
while ( $blog_posts->have_posts() ):
$blog_posts->the_post();
// Do stuff with each post
echo get_the_excerpt() . "<br>";
endwhile;
wp_reset_postdata();
endif;
WordPress Codex is a great resource for WP development. The WP_Query class is incredibly powerful and well-documented here: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Related Posts:
- Use template of parent category for single post sub-categories
- How to show post(excerpt) from specific category on wp page?
- How only display all post related to category
- Different template for posts of all subcategories of category
- Category Template: Need to display different content on first page of archives
- How do I stop the loop from repeating in my category template?
- Give posts a particular template based on the assigned category
- Related post not showing table of content
- Nothing appears using get_the_excerpt() in category.php
- Show category post with excerpt text
- Display the first post’s comments of category in comments.php template
- how to style an individual page in a category [duplicate]
- How to get subcategories from category slug?
- Remove current category from post but display all others
- How show categories in admin and get that selected to show posts in index
- Showing categories and subcategories with posts
- Change default category when I publish a post
- store posts_id of category into a varable?
- Hide a specific post from a page template
- How to display two random-post sections that are each under their own category
- How can you display all sibling categories to a post?
- Loop doesn’t exclude the specified category in home page
- Tell WP to use a specific template file in posts
- Display posts of specific category term
- Widget that shows categories with posts numbers
- How to create a sub post?
- Displaying post excerpt using wpdb query
- Post Image not displaying in category view
- How to make different custom post layouts?
- How do I show posts from another wordpress installation?
- How to disable the_excerpt from one post
- get posts from Custom Post Type & Category
- The_excerpt() doesn’t parse – how to change that?
- Trying to edit archive.php to only show post extract, with featured image
- Category page when using static front page
- Latest posts by category — how to exclude current post?
- Why won’t pagination work?
- How do I include the category next to the title of a post?
- Relative number of post in category
- How to create a “latest news” page showing a list of posts from blog category
- Is it possible to give the user the chance to select between two single template files to use in a post?
- WordPress bulk category select when publishing post
- Create a custom posts page
- Exclude some categories from listing on the current post
- how to set social icons to product / post template (Auros theme)? [closed]
- How to show a custom taxonomy in the theme?
- How to import nested categories from XML file?
- How to identify and hide/remove an element from a WordPress page [closed]
- wordpress posts template remove default template from menu
- Show metabox value last post excerpt, title and link
- how to hide empty fields of post category description?
- how can i display my posts alphabetically?
- Hook for changing excerpt content when excerpt not set
- if in category but only with post meta
- How to get post with associated categories and tags names instead of ids with rest api?
- Force a specific template as default
- Display a mixed list of posts and media
- Migrate posts from category and sub-category via SQL
- Parent category / child category posts
- Change the number of excerpts displayed in search results layout
- Posts Missing in Dashboard after update
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Sort by last word in title
- showing posts of an specific category in admin custom menu with style of admin posts section
- Display post number by category
- singular posts using archive styling
- the_excerpt is displaying excerpts of every post
- Change Post Title For Specific Category
- Display selected categories onto post page
- How to call posts under a specific category on static front page?
- How to have more than one page for your posts if you have 8 posts but can store max 4 on a page
- Extract wordpress posts content and category content
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Why excerpt is Displaying same in Random Posts list
- How to get post with slug and exclude categories
- All categories displays the same posts
- Having pages after specifying post_type post
- Unable to differentiate between two categories under custom post type on single.php
- In what context should Categories and Tags be used
- Display a post via template
- Exclude post category in a blog page
- Show posts on front page only
- list posts from two categories on a page – plugin not working
- Single post full screen template not inheriting WordPress role permission
- How to set a certain Custom Template to a Single Blog Post
- Retrieving posts by their date and category
- Get latest post from categories
- How to create a playlist for audio associated with posts per category
- Are post, page and category IDs unique to each other?
- Change the background of each post according to the category
- Static pages not working
- Post-Archive like a page in a specific subdirectory
- List all native posts in template page?
- Programmatically add posts from specific category to menu
- WP_Query of Category Not Showing First Post
- content summary of a post disappears If an images added at the beginning of the post. how to solve it?
- Sidebar on single.php not showing up
- How to Featured content with images in home page?
- Post is in descendant category not working in home.php
- WordPress displays post on subcategory only