現在の投稿のスラグ名を取得
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$terms = wp_get_object_terms( $post->ID, 'タクソノミーを入れる' ); //$post ->IDで現在の投稿のIDを取得 foreach ( $terms as $term ) { $termslug = $term -> slug; //スラグ名取得 } remove_all_filters('posts_orderby'); //並び換えのプラグインを入れている場合は、そのフィルターを除去する $myposts = get_posts('numberposts=3&post_type=products&taxonomy=タクソノミー&term=' . $termslug . '&orderby=rand'); foreach($myposts as $post): ?><A href="<?php the_permalink() ?>"><?php the_title(); ?></A><? endforeach; wp_reset_query() |
同カテゴリー(ターム)の投稿をランダムに3件取得しています。
numberposts=3 // 取得する件数
post_type // 投稿タイプ。カスタム投稿名
taxonomy //タクソノミー
order // 投稿順 ランダムに表示したい時は order=rnd