You’ve already got code to figure out which category you want to show posts from, here is how you would grab all the posts in that category:
// create a query to grab our posts in category of ID $postcat
$q = new WP_Query(array( 'cat' => $postcat));
if($q->have_posts()){
// foreach post found
while($q->have_posts()){
$q->the_post();
// code for displaying each post goes here
}
// cleanup after the WP_Query, reset the post data
wp_reset_postdata();
} else {
// no posts were found!
}
Never use query_posts
to do your queries, always check if any posts were actually found, and always cleanup after yourself.
For more arguements for queries, see here:
Related Posts:
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Use template of parent category for single post sub-categories
- 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?
- Post Image not displaying in category view
- Latest posts by category — how to exclude current post?
- Give posts a particular template based on the assigned category
- Remove Featured Image from posts in specific category?
- How to show category image if no featured image is set?
- Display the first post’s comments of category in comments.php template
- how to style an individual page in a category [duplicate]
- excerpt in template for specific page
- How to display two blog categories as separate sections on one page?
- How to create new post content templates for my users?
- How to make the first post in the loop be styled like a “new / featured” post?
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- How to create a template for Pages?
- get_the_category listing in hierarchial order
- Is it possible to add/tick a category to a post when it is created?
- Excluding posts not working
- Hide posts belongs to few categories in homepage
- How to check if single.php has already called the_post_thumbnail function
- why does wordpress ignore the post args?
- post category in wp_insert_post
- Limit the number of posts a category can have – newest post goes in, oldest one drops out, possible? plugin?
- posts not showing on index.php
- Getting only the URL of the post thumbnail
- How to get subcategories from category slug?
- Remove current category from post but display all others
- Remove Featured Image & All Media Uploaded to the Post
- How show categories in admin and get that selected to show posts in index
- Get Post’s first image using Short-code
- Showing categories and subcategories with posts
- Change default category when I publish a post
- store posts_id of category into a varable?
- related author post thumbnail shows post thumbnail
- 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?
- Admin – no Featured image choice in create new/page|post
- preg_replace not removed “class”
- How to make different custom post layouts?
- How do I show posts from another wordpress installation?
- get posts from Custom Post Type & Category
- Category page when using static front page
- 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
- how to hide empty fields of post category description?
- how can i display my posts alphabetically?
- 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
- how to give multiple post thumbnails to a post
- Display a mixed list of posts and media
- Migrate posts from category and sub-category via SQL
- Parent category / child category posts
- 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
- Using wp-cli and delete everypost first image
- How to display post title inside thumbnail?
- 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
- Post Title to featured Image ALT
- 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