Reordering the way you want is really pretty trivial. Proof of concept:
$p = array(1,2,3);
var_dump($p);
array_push($p,array_shift($p));
var_dump($p);
With the WordPress code:
$p = get_posts('posts_per_page=3');
array_push($p,array_shift($p));
var_dump($p);
To make it more interesting, you can do the same with a filter. Since get_posts()
uses wp_query()
you can use the post_results
hook to reorder the results.
function post_shift_wpse_166761($p) {
remove_filter('posts_results','post_shift_wpse_166761');
array_push($p,array_shift($p));
return $p;
}
add_filter('posts_results','post_shift_wpse_166761');
$p = get_posts(
array(
'suppress_filters' => false,
'posts_per_page' => 3
)
);
var_dump(wp_list_pluck($p,'ID'));
Note that you also have to pass a suppress_filters
argument to get_posts()
.
Related Posts:
- Very slow query
- Sorting Grids with Essential Grid and Events Manger
- Does meta_query work within get_posts array?
- How to show more than 5 posts?
- How to optimize my query filtering out unwanted data?
- Remove posts from query for events whose start date has passed
- get_posts() loop returns the same the_title() for each post
- List all posts from past week grouped by sub-category
- Order posts by custom field DATE value
- How do I see the mysql query generated by get_posts( $args )?
- Create Indexes for Slow Queries
- Can’t seem to do combined query AND sort?
- sort query results by newest
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- pre saved posts query from db options table
- How to manage a particular “order by” for get_search_query()?
- How to rearrange a pool of posts joined using two queries?
- Can I include get_posts in this array?
- How to “orderby” the first array in a meta_query that uses multiply keys?
- Sort query_terms_list for post_tags alphabetically
- Order posts ascending from posts in array
- How can I get posts by 2 meta keys, prioritising one of them?
- Orderby event date (if it exists) or post date (if it doesn’t) – how to reorder posts based on meta value OR date
- Category_in return empty
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Sort order in get_posts [closed]
- Sort loop with query in the link
- Query posts alphabetically within this function
- Ascending & descending posts on same page with IF statement
- Elementor – Sort by name
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to display SQL query that ran in query?
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to Optimize WP site for millions of posts
- Get the ID of the latest post
- How to get comments by post ID?
- WP_Query vs get_posts
- Differences between wpdb->get_results() and wpdb->query()
- Is there a way of increasing the speed of this query?
- Random sort within an already sorted query
- Get all image from single page using this query
- How can I query all users who registered today?
- Get Terms by IDs with IDs order
- Reversing the order of posts AFTER the query is performed
- Sort custom post type list table by display name of a user id stored as post meta value
- what are the numbers between curly brackets in search query
- simple sql query on wp_postmeta very slow
- Using WordPress public query variables
- How to return results of a get_posts() in explicitly defined order
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Sort posts by category name and title
- Create pagination and order according to alphabet
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- How to organize and cache additional data associated with terms?
- wordpress query – orderby child post date
- How many WordPress SQL Queries per page?
- How to display Section for certain time
- Add multiple value to a query variable in WordPress
- Search custom post type by meta data
- Custom query_var causes displaying posts archive on front page
- How to know if get_posts() failed?
- Slow wp_enqueue_media()
- Multipart/formatted MySQL query problem
- What is the most efficient way of implementing a favorite post system?
- Remove [gallery] shortcode altogether
- Compare two numeric custom fields
- wp_dropdown_categories with multiple select
- Advanced Custom Fields – Query Efficiency
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Get posts by meta data OR title
- Query by one meta_key and sort by another (possibly NULL value)
- How to tune search argument in WP_Query to show only exactly the same results?
- Sort X categories by last update and show image
- Custom query filter not working on woocommerce category page
- How to delete a transient on post/page publish?
- query multiple taxonomy and show post count
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Query & Sort Comments by custom comment meta
- Fulltext search in posts sorted by relevancy
- How to get my loop to pull posts into three columns
- How do I sort multiples pages?
- How to display lastest post date in the homepage?
- Custom $wpdb Query for Custom Post Type by Category
- Limit number of pages in pagination
- Get a user’s most recent post title
- Categories and products in random order
- add_query_arg() XSS Vulnerability
- Count user posts by user ID, Post type and Post status
- Can’t pass table to $wpdb->prepare
- Query set using tax_query with relation ‘OR’ modifies category object?
- $query->query_var[‘post_type’] not set for pages
- is_archive() doesn’t work on public query var archive pages?
- How to extract all ID variables from a query string?
- When add_query_arg() is necessary?
- Different Main Navigation per category