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()
- Get current menu_order
- Get current post id in functions.php
- Random sort within an already sorted query
- Search by Hyphen
- Exclude drafts in all() view of edit.php
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Sort post by attributes ‘order’
- Keep getting same permalink with WP_Query?
- How to query posts with current or future date only
- WordPress Number of Posts Not Changing With posts_per_page
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Exclude posts with specific meta_value while sorting by a separate meta_value
- Problem ordering posts with numbers for titles numerically E.g. 1, 10, 100
- Display custom post types by date field
- Display the latest posts, published in the last hour, with WP_Query
- Custom Order in WP Query
- Fetch posts from current week (Sunday to Saturday)
- Search query – exact post title match
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- How to get most recent commented post above new submitted post in WordPress?
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- Exclude posts from featuring
- Lazy Load using WP_Query pagination
- Only display a certain number of posts, dependent on how many posts there are available in a query
- AJAX filter posts by year
- Automatic post deletion
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Yearly archive page for future year
- How can I show many posts an author has per week?
- Ajax load more button in Recent posts widget
- Custom WP_Query with complex ‘post_status’ argument
- is there a way to show the the post title after the image?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Pausing and Resuming WP_Query results
- Select only post id and meta value with WP_Query
- how can i change WP main archives loop to sort by name or title
- While loop articles – if statement order
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- why the same code got different results when using query_posts in functions.php and index.php
- How to get posts published on the latest date?
- Page and post loop same template
- Show metabox value last post excerpt, title and link
- WP_Query: Show 10 posts in date order, first three random
- get_previous_post() while accounting for sticky posts
- Related Posts function not working
- wp_query if have posts show date but not in loop
- Custom WP_Query not working correctly
- Echo the number of posts being displayed
- WP_Query of Category Not Showing First Post
- Creating a related posts section in wordpress inside a default post
- 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
- Why sorting posts doesn’t work properly?
- How to create loop of posts except post ID defined via ACF field
- the wp_post_update isn’t working all the time
- Display specific posts based on an ID of another post
- a WordPress connected to 2 database
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- WP_Query that targets all categories
- Fill the exclude array() in get_posts()
- Double loop output
- Ajaxify Post Sort
- Get current user, change users post status to published
- Displaying a specific sub-category’s posts from wp_query
- Custom layout manager for posts
- Display WordPress Post By Date
- GUID to related post not in current language
- How to make post button to a random post
- Get results from the main wp_query
- Advanced Post Display/Pagination/Ordering
- Where is object, property or label in the database that controls the order of the posts being displayed?
- Pagination for custom query won’t let me back on page 1
- WP_Query retrieve custom posts but not the post showing
- WP_Query based on a custom field result
- How to get single post by one author?
- List posts related to category on a div [closed]
- WP_query sort by custom meta_key “price”
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]