orderbyのランダムrandがPost Types Orderによって効かない
2016年11月24日関連商品をランダムで5件表示したかった
ある商品の詳細ページで関連する商品として、ランダム5件の商品を下の方に表示させようと思ってたらハマった。

原因はPost Types Order
https://wordpress.org/plugins/post-types-order/
このプラグイン自体は管理画面から順番を変更出来る非常に便利で、何も悪くないけど、この子が原因でランダムにしたいところまで影響を与えてしまってた。
解決:フィルタをカットする関数をquery_postsの直前に入れる
remove_all_filters('posts_orderby');
この関数を入れてあげると恐らくorderbyをリセットしてくれる。
なのでその後にquery_postを設定してあげるとOK。
<?php
$args = array(
'posts_per_page' => 5,//表示件数
'post__not_in' => array($post->ID),
'tax_query' => array(
array(
'taxonomy' => 'fugafuga',
'field' => 'slug',
'terms' => 'hogeohge',
),
),
'orderby' => 'rand'
);
remove_all_filters('posts_orderby');//本日の主役
query_posts( $args );
if (have_posts()) : while (have_posts()) : the_post();
/* ぐるぐrぐるぐr
----------------------------------------------- */
endwhile; endif;
wp_reset_postdata(); wp_reset_query();
?>