我正在使用一个相关帖子PHP WordPress查询,但在排除类别时遇到了问题。我试过排除viacat
和category__not_in
以及作为和不作为数组。我设置的错误是什么?
<?php $orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
\'cat\' => array(-6,-173,-174),
\'category__in\' => $category_ids,
\'category__not_in\' => (6, 173, 174),
\'post__not_in\' => array($post->ID),
\'posts_per_page\'=> 3, // Number of related posts that will be displayed.
\'orderby\'=>\'rand\' // Randomize the posts
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo \'<ul class="realted-article">\';
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<li>
<a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
</a>
<div class="perfect-related_by-category">
<strong><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></strong>
<a href="<?php echo get_permalink();?>">
<?php if(get_field(\'summary_text\')==\'\')
{echo substr(strip_tags(get_the_content()),0,90);}
else{echo strip_tags(get_field(\'summary_text\'));}?>
</a>
</div>
</li>
<? }
echo \'</ul>\';
} }
$post = $orig_post;
wp_reset_query();
?>