Php WordPress循环帖子没有特色标签

Php WordPress循环帖子没有特色标签,php,wordpress,Php,Wordpress,我想循环后,这是没有特色的标签。我想在主循环(查询)中使用此选项,它具有以下代码: if ( have_posts() ) : /* Start the Loop */ while ( have_posts() ) : the_post(); endwhile; endif; 谢谢大家。试试这个。您想使用pre_get_posts过滤器修改主查询。然后,可以将分类查询添加到主查询参数以对其进行筛选 您是使用内置的帖子标签创建一个名为“特色”的标签,还是以其他方

我想循环后,这是没有特色的标签。我想在主循环(查询)中使用此选项,它具有以下代码:

if ( have_posts() ) :

     /* Start the Loop */
     while ( have_posts() ) : the_post();

     endwhile;
endif;

谢谢大家。

试试这个。您想使用pre_get_posts过滤器修改主查询。然后,可以将分类查询添加到主查询参数以对其进行筛选

您是使用内置的帖子标签创建一个名为“特色”的标签,还是以其他方式设置特色帖子?如果你只是在寻找带有“特色”标签的帖子,那么下面的代码将显示所有带有“特色”标签的帖子


我找到了解决办法

我应该在functions.php或index上粘贴这些代码吗?我的主要目的是在主查询中显示没有特色标记的帖子。这将放在functions.php文件中。如果“显示帖子”指的是format metabox中的选项,则需要将筛选所依据的分类从
post\u标记
更改为
post\u格式
add_action( 'pre_get_posts', 'modify_main_query' );

function modify_main_query( $query ) {
    // Check if on frontend and this is the main query
    if ( ! is_admin() && $query->is_main_query() ) {
        $tax_query = array(
            array(
                'taxonomy'         => 'post_tag',
                'terms'            => 'featured',
                'field'            => 'name',
                'operator'         => 'EXISTS',
                'include_children' => true,
            ),
        );

        $query->set( 'tax_query', $tax_query );
    }
}
/* The Query */
$tag = get_term_by('name', get_theme_mod('blog_filter_tag', ''), 'post_tag');
$args = array(
    'tag__not_in' => (int)$tag->term_id
);

query_posts( $args );