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:

  1. 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'.).
  2. 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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -