我是靠谱客的博主 呆萌小笼包,这篇文章主要介绍wordpress 自定义循环 按指定 array(ID数组)排序,现在分享给大家,希望可以做个参考。

实际应用:

$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数组)排序 

$args = array(
'post_type' => 'post',
'post__in' => array(3,5,2),
'orderby'=>'post__in'
);
$the_query = new WP_Query($args);

他会按ID 3 5 2 排序

最后

以上就是呆萌小笼包最近收集整理的关于wordpress 自定义循环 按指定 array(ID数组)排序的全部内容,更多相关wordpress内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部