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
Post a Comment