mysql - WordPress get specific posts in arbitrary order -
right now, i'm doing:
$posts = get_posts(array('post_type' => 'page', 'post__in' => array(1, 3, 2, 9, 7)));
and having 2 issues:
- post 3 of
'post_type' => 'post'
, doesn't selected, want it! if leave out'post_type' => 'page'
, post 3 selected (because must assume 'post_type' => 'post'.). i want able order posts arbitrarily ids. if knew how use mysql, do:
select * wp_posts id in (1, 3, 2, 9, 7) order find_in_set(id, '1,3,2,9,7');
but, how should wordpress?
first fetch posts arbitrarily ids , loop through posts
you can in way:-
$posts=$wpdb->get_results("select id $wpdb->posts id in (1, 3, 2, 9, 7) order find_in_set(id, '1,3,2,9,7')"); $count=count($posts); ($counter=0 ; $counter < $count; $counter++) { $post=get_post( $posts[$counter]->id, $output ); //do stuffs posts }
hope helps
Comments
Post a Comment