If you want your posts based on different categories you should use category_name
or cat
as category id. For example;
<?php $test = new WP_Query('cat=1&showposts=1'); // where 1 is the id of your cat ?>
Or
<?php $test = new WP_Query('category_name=errands&showposts=1'); ?>
Also, you need to call wp_reset_postdata();
after each WP_Query
. I hope this helps
More on how to use categories in WP_Query
Related Posts:
- Inject post (from specific category) between posts in Loop
- Count number of published posts by type
- Get taxonomy terms only of the WP_Query current posts
- Hide post if matches current month and year
- How can I use wp_query to show all product data using just the products ID?
- How to store post ID’s in cookie or session to display the same posts later
- WP_Query: getting posts where custom field exists
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- array_rand not working correctly?
- WP_Query() load selected post
- Wp Query : Order by distance lat,lon
- WordPress sorting posts by date and title using a dropdown
- posts_per_page displays only 2 posts instead of 4 posts
- Query on a repeater date (acf)
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Getting info about selected posts using one WP_Query
- How to display last whole post on the homepage
- Only Get A Certain Number of Posts From WP_Query
- insert thumbnail image from php script
- Weird Behaviour: Not all WordPress Posts appearing
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- How to modify this function to exclude also the post belonging to a specific category?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- get_the_content if it contains multiple lines it results in SyntaxError
- Looking to exclude blog posts from category Previous/Next buttons
- Alter secondary loop to exclude posts from current page category
- Automatic Excerpt Not Working
- Using a javascript file to access a get posts array
- WP_Query with the “offset” argument
- Display Post co-authored in Author Page
- Sorting Posts | Alphabetical Order
- WP_Query is printing out only one post when posts_per_page is set to multiple
- Looking for most performant way to execute several similar WP queries within shortcodes
- Trying to make php run in a post
- Remove posts after a given amount of time
- Hide wordpress field if data is empty in post!
- How to use an associative array in post__in with WP_Query?
- How to show part of the_content?
- How to set a min number of words for a blog post
- Get post id in a function when edit/add a post
- WordPress, AJAX and pre_get_posts using conditional tags
- Exclude posts based on meta value
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Remove echo from shortcode
- 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
- unable to use ‘new WP_Query’ in AJAX call
- Pagination on Custom Post
- $wpdb returns duplicate posts
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- How to hide posts of a specific custom category in WordPress?
- Do I need to edit my theme in order to change the title of my blog page?
- Add new post in existing categories using wp_insert_post
- How do I add more options to the post-new.php page?
- WordPress WP_Query without query GET parameters
- Get the id of all images in a post
- Four posts per row [closed]
- Need help removing […] after excerpt
- Remove Post if Advanced Custom Field is checked to fix paging
- displaying a fall back query if there’s nothing in the post-type category
- Pagination in single.php
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- wp_query with multiple arguments with AND
- Nested Queries of decreasing specificity
- Wrong pagination results, page counter resets when navigating
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Load more posts using AJAX based on posts inside WP_Query
- in_array not working on dev server but works on localhost
- WP query posts BUT show the most recent and one per author
- Define global custom post
- How to get post image caption by index
- Is there anyway I can call the year once?
- Check $post->ID against multiple values
- Posts missing on author page
- How to allow users to save list of posts in wordpress?
- Search for single post by 2 tags
- How to center all text body in single.php at once?
- Woocommerce Related Product by 2 taxonomy
- Get current_post in reverse order with pagination
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Basic PHP question (displaying post title over thumbnail) [closed]
- Can’t get data from audio media
- WP_Query count of different meta key values [duplicate]
- Post from front end form to post_meta
- media_handle_sideload() returned post_id being incremented
- Saving Post redirects to 404 page when php $_GET variable in post body
- Keeping the previous get value and add another value when submitted
- link to page_for_posts
- Pagination in category.php not functioning
- How to create a loop that will display one post and stop?
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- How to sort search result by post_title, then by post_content
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress