Php 从自定义post类型循环中删除标记
我目前正在使用下面的代码显示我的类别中的所有页面:Php 从自定义post类型循环中删除标记,php,html,wordpress,loops,Php,Html,Wordpress,Loops,我目前正在使用下面的代码显示我的类别中的所有页面: <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <a href="<?php echo get_permalink(); ?>"> <?php echo "<div class='col-md-6' style='margin-bottom
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php echo get_permalink(); ?>">
<?php echo "<div class='col-md-6' style='margin-bottom:20px;'>"; ?>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12 nopr"><?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'testclass')); ?> </div>
<div class="col-md-6 col-sm-6 col-xs-12 categorytiletext2">
<div class="testdiv">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php echo "</div>"; ?>
</a>
<!-- If there is no posts, display an error message -->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<!-- If there is no posts, display an error message -->
这非常有效,但我现在已经在这些页面中添加了标签。我需要做的是从循环中删除某些标记。例如,我的标签名为maintag
我试图补充以下内容:
<?php $my_query = new WP_Query(array('tag__not_in'=>array('maintag'), 'category_name'=>'Clients', 'orderby'=>'title', 'order'=>'ASC')); ?>
但这不起作用
这是否需要由ID完成
编辑:
新代码,仍然不工作
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $tag_object = get_term_by('slug', 'sector1', 'post_tag');
$tagID = $tag_object->term_id;
$my_query = new WP_Query(array('tag__not_in'=> array($tagID), 'category_name'=>'Clients', 'orderby'=>'title', 'order'=>'ASC')); ?>
<a href="<?php echo get_permalink(); ?>">
<?php echo "<div class='col-md-6' style='margin-bottom:20px;'>"; ?>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12 nopr"><?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'testclass')); ?> </div>
<div class="col-md-6 col-sm-6 col-xs-12 categorytiletext2">
<div class="testdiv">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php echo "</div>"; ?>
</a>
<!-- If there is no posts, display an error message -->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<!-- If there is no posts, display an error message -->
如果maintag是slug,则在第一个参数中使用“slug”,如果是name,则使用“name”而不是slug
链接:
使用pre_get_posts从分类页面上的循环中删除带有特定标记的帖子,我在哪里使用它?
$tag_object = get_term_by('slug', 'maintag', 'post_tag');
$tagID = $tag_object->term_id;
$my_query = new WP_Query(array('tag__not_in'=> array($tagID), 'category_name'=>'Clients', 'orderby'=>'title', 'order'=>'ASC'));