【问题标题】:Wordpress Orderby rand not workingWordpress Orderby rand 不工作
【发布时间】:2013-02-08 10:32:23
【问题描述】:
remove_all_filters('posts_orderby');
$args = array(
    'post_type' => 'attachment',
    'numberposts' => 6,
    'orderby' => 'rand',
    'exclude' => get_post_thumbnail_id(),
    'post_parent' => $post->ID
);

有人可以向我解释为什么'orderby' => 'rand' 部分不起作用吗?

谢谢!

【问题讨论】:

  • 你在哪里使用这些参数?
  • 在我的侧边栏中。它是生成一组随机的示例徽标。它适用于所有其他 $args 但不适用于“rand”位
  • 你在wp_query()内部使用它吗?
  • 没有。我认为这无关紧要,因为它适用于数组的所有其他部分。
  • 在 $args 之后,我有 $recent_posts = get_posts($args); foreach( $recent_posts as $recent ){ echo wp_get_attachment_image( $recent->ID, 'full' ); }

标签: php wordpress


【解决方案1】:

找到了。我需要将'order' => 'post_date', 添加到$args。感谢@BenM 的帮助!

【讨论】:

    猜你喜欢
    • 2012-11-07
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    相关资源
    最近更新 更多