php - How to re-order array elements if there is a specific key? -


it seems wordpress wp_query doesn't provide option of order post_status. , want list private posts before other posts. posts array looks this:

$posts = array(              0=>object{                      ....                 },              1=>object{                      ....                },             ....          ); 

each post object has key of 'post_status'. want move post beginning of array if value 'private', . how?

use usort():

usort($posts, ($a, $b) {     return ($a->post_status < $b->post_status) ? -1 : 1; }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -