$p_id_cookie = $_COOKIE['p_id_cookie']; if(isset($p_id_cookie)){ $arr = json_decode($p_id_cookie); } //print_r(array_reverse($arr)); $args = array( 'post_type' => 'post', 'post__in' => array_reverse($arr), 'orderby'=>'post__in' ); $the_query = new WP_Query($args); if ( $the_query->have_posts() ) : // Start the Loop. while ( $the_query->have_posts() ) : $the_query->the_post(); /* * Include the post format-specific template for the content. If you want to * use this in a child theme, then include a file called called content-___.php * (where ___ is the post format) and that will be used instead. */ get_template_part( 'content', get_post_format() ); endwhile; // Previous/next page navigation. twentyfourteen_paging_nav(); else : // If no content, include the "No posts found" template. get_template_part( 'content', 'none' ); endif; wp_reset_postdata();
如下代码 wordpress 自定义循环 按指定 array(ID数组)排序 php
$args = array(
'post_type' => 'post',
'post__in' => array(3,5,2),
'orderby'=>'post__in'
);
$the_query = new WP_Query($args);
json
他会按ID 3 5 2 排序数组