現在「同じカテゴリで、今の記事を抜いてランダムに表示する」
というのを
<?php global $post; $terms = get_the_terms($post->ID, 'category'); foreach( $terms as $term ){ if($term -> parent == 0){ $parent_cat = $term -> slug; break; } } $args = array( 'post_type' => 'post', 'taxonomy' => 'category', 'term' => $parent_cat, 'orderby' => 'rand', 'post__not_in' => array($post->ID) ); ?> <?php $myPosts = get_posts($args); if($myPosts) : ?>
で行っているのですが、ここで「ただし特定のカテゴリを除く」を実装したいです。
'cat' => '-3'
とかのようですがこれではうまく行かず、、、
どう記述すればよいでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/03 01:06