wordpress 对已排序的随机数据进行升序排序 |
您所在的位置:网站首页 › 提款机键盘数字排序 › wordpress 对已排序的随机数据进行升序排序 |
我的要求 例如 - 我有 20 个帖子 (wordpress) - 我需要按升序排列 10 个帖子(按自定义元键排序) - 然后我需要显示已排序数据中的随机 1 个帖子(来自 10 个帖子) 我的代码在 function.php add_filter( 'the_posts', function( $posts, WP_Query $query ) { if( $pick = $query->get( '_shuffle_and_pick' ) ) { shuffle( $posts ); $posts = array_slice( $posts, 0, (int) $pick ); } return $posts; }, 10, 2 );在模板页面 $args =array('post_type' => 'products', 'posts_per_page' => 10, 'meta_key' => '_showoption_', 'orderby' => 'meta_value', 'order' => 'asc', 'no_found_rows' => 'true', '_shuffle_and_pick' => 1 , ); $my_query = new WP_Query( $args );我的结果:从 10 个升序帖子中获得 1 个帖子:但我需要从这 10 个帖子中随机选择 1 个 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |