I’m not sure if it’s possible to do this in a single query in WordPress. You could potentially split it into two like below:
<ul>
<?php
global $post;
// Get posts by selected post ids
$args = array(
'posts_per_page' => -1,
'post__in' => [12345,12543],
'orderby' => 'post__in'
);
$myposts = get_posts($args);
foreach ($myposts as $post) : setup_postdata($post); ?>
<li>
<?php echo get_the_ID(); ?>
</li>
<?php endforeach;
wp_reset_postdata();
// Get latest posts excluding selected post ids
$args = array(
'posts_per_page' => -1,
'exclude' => [12345,12543]
);
$myposts = get_posts($args);
foreach ($myposts as $post) : setup_postdata($post); ?>
<li>
<?php echo get_the_ID(); ?>
</li>
<?php endforeach;
wp_reset_postdata();
?>
</ul>
Related Posts:
- How do I reorder (pop and push) items from WP_Query?
- Reverse chronology of post listing
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- How to order posts by meta_value and title
- how to get post order by post id wp_query?
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- WP_Query sort by meta_value_num or date
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Get query result according to merged array
- Order by ‘s’ using WP_Query()
- Should we trust the post globals?
- Get first post from wp_query
- Sort posts by popularity/page views
- Querying post from a multisite network
- How to query serialized array by comparing greater than (>=)?
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- post__in for get_posts with a dynamic array
- How to sort posts by last name (2nd word) on ONE category only?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Post content being duplicated by the_content();
- Specific loop in Shortcode
- Sort posts by activity date
- How to add padding between posts
- prevent showing posts of an specific category in admin posts section
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Search widget breaks when using multiple loops?
- How to change bulk post status
- Add few specific post ids to wp_query
- WP_Query posts_per_page ignored
- wp_query ‘s’ parameter does not work with custom post type
- WP Query related posts by current page Tag ID
- Accessing post->ID outside of the loop for listing child pages
- WP Query – duplicated posts once including tags in search results
- Reset Popular post query?
- Query Posts multiple conditions
- Why orderby=”date” does not support manually changed posts?
- how to get posts ids inside pre_get_posts filter?
- Future post ID not showing
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- recent posts for different categories
- Change post order random through out the entire WordPress
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- Removing noindex posts from wp_query
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- how can i change WP main archives loop to sort by name or title
- Using wp_list_pages() after calling query_posts()
- Why are my paginated posts always returning the same results?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Loop doesn’t exclude the specified category in home page
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Migrate posts from category and sub-category via SQL
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- WP_Query: Show 10 posts in date order, first three random
- Exclude some posts from displaying in wp_query based on some condition
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- Conflict array_splice on loop and query in widget
- WP_Query of Category Not Showing First Post
- Change content off every sixth element
- WP_Query get posts in custom database table [duplicate]
- WP query taxonomy optimization
- WordPress Query – Display 5 posts (same post type), each from a given tag
- While loop in functions.php outputting the_title() of each post on frontpage
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- a WordPress connected to 2 database
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Ajaxify Post Sort
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- Get current user, change users post status to published
- WordPress text field in array problem
- Display WordPress Post By Date
- GUID to related post not in current language
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- How to show the posts list into a static page? Problems to use the loop into a static page
- Query category-specific, paginated posts and allow viewer to change sort order
- Make assigning post to a specific category equivalent to assigning it to all categories
- Multiple loops on a Search result page?
- WP_Query retrieve custom posts but not the post showing
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- WP_Query based on a custom field result
- How do I show the post title if an advanced custom field hasn’t been used?
- WP_query sort by custom meta_key “price”
- How add class the_content();?
- Add custom PHP (no-SQL) filter to WP_query
- date_query returning only the most recent post instead of the post published before today
- How to make WP_Query faster when getting a post from one year ago?