I think you need to use post__in
. The code will be something like:
$args = array(
'post__in' => array( 1, 2 ),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'no_found_rows' => true,
'posts_per_page' => 2,
'post_status' => 'any'
);
$query = new WP_Query($args);
Related Posts:
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query and next_posts_link
- Sanitation needed for WP_Query or get_posts calls?
- how does $wpdb differ to WP_Query?
- replace the WP_Query class in the main query
- Get posts with condition on comment meta value
- WP_Query sort by comment meta data
- Limit search results to exact match
- WP_query ‘orderby=none’ Problem
- Display different number of posts from one category on the different pages
- How to display child posts in the parent category
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Order terms inside a select dropdown
- How to speed up wp_query, took more 5s to run against 100k posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Ordering by meta_value AND date NOT WORKING with wp_query
- Transient caching for wp query
- WP_Query orderby breaks when using AJAX?
- Custom WP Query from meta_value stored as serialised array
- Get List of all the Authors
- How to check if a post “does not have term” in conditional statement?
- Detect featured image among the attached images
- Pass arguments to WP_Query using “set” method
- get_posts – get all posts by array of author
- wp_query not searching with apostrophe
- pre_get_posts Remove tax_query Completely
- Query “Category A” + 1 post from “Category B” – how?
- How to combine two or more WP_Query?
- Assigning a meta_query value based on regexp to wp_query fails
- Getting Taxonomy inside WP_Query Loop
- Nested tax_query that allows specified categories OR tags, but NOT other categories
- How to delete taxonomy term when a wordpress user is removed?
- Custom query based on meta key – Reduce three states to two in results?
- WP_Query custom query showing only 10 posts on all pages
- Not getting metavalue
- Ajax load more posts – WP_Query parameters not working
- How to display multiple custom fields with the same meta_key in an ascending order?
- Using the_post_thumbnail resets current loop item ID
- Meta_query with multiple keys and multiple values
- Posts not showing per category after WP_Query?
- wp_query exclude word and category
- Assign Json file to WP_Query
- How can I query users by custom role?
- How do I query for posts by partial meta key?
- WP Query to have sticky posts first, with pagination and having a joint ‘posts per page’ arg with main loop
- New WP_Query calls Pre_get_posts filter twice
- How to increase load time of an archive/search page (WP_Query)
- Removing duplicate values between two wordpress queries
- Issue with front page navigation after upgrading to 3.4
- Ordering posts by an array
- Prevent author bio page from showing in search results
- Changing the default wp_search_stopwords
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- WordPress Custom Search Form Displaying Unexpected Results
- WP_Query array key / value pairs?
- Get posts from multiple tax terms
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Limit number of posts in loop
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- WP_Query offset is returning post from prevois loop
- Tax query is not working!
- Does WP_Query ‘responds’ badly to empty arguments?
- Does putting queries within loops cause an issue on WordPress?
- How to create Page templates for showing Blog posts in different layouts?
- Determining what post is displayed out of total posts found
- Reordering content using a meta value
- Adding query parameter to archive page returns 404
- Optimising WP_Query with ACF Fields
- Is it normal that get_post() gets run 300 times and the content of those posts aren’t visible?
- WordPress AJAX Request returns 400
- Using wpdb prepare with a variable, turns it into a big string
- WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination
- SQL to join u3g_users & u3g_meta_value with repeating data
- How to get meta key list efficiently?
- Get posts having meta value between two numbers
- update_post_meta performance in a loop woocommerce
- Separate by Category Post Type
- ACF: using two loops, the_field returns field content from another loop
- Using modified ‘meta_key’ to set ‘orderby’ in WP_Query?
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- query_posts() doesn’t seem to be called in my page
- Query posts in current category but not attachment format
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- Slow getting posts from category
- Pagination not working with WP_Query (creates links but no page)
- WP Query posts__in not working with array
- query_posts with sorting on a custom datestamp
- Query Posts by date range with fixed beginning and end
- Avoiding page loop
- Query Users by post count, last 30 days and display each users post count according to post type
- Is it possible to use WP Query to orderby custom meta value and custom taxonomy?
- how do I exclude child categories from a wp_query?
- Display all custom meta field values from the database using ACF Repeater
- How to create a loop inside WP_Query?
- how to show only catergory titles on a page in wordpress