最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Add a specific category in Elementor Category Archive Template page for a Widget - Stack Overflow

programmeradmin0浏览0评论

In the archive page, I would like to show in a loop grid widget ONLY the posts that belong either to the displayed archive category and also to a specific category which slug is "special-one", meaning that they have to be from both categories (operator AND). So I have set up an archive page template in Elementor theme builder. Just in that single loop and not as default for the archive page.

I Used the following code:

add_action( 'elementor/query/special_archive_filter', function( query )
   if ( is_category() )
       $category_id = get_queried_object_id();
       $special_category_id = special-one;
       $categorie query->set( 'tax_query', array(
            array(
                'taxonomy' => 'category',
                'field'    => 'id',
                'terms'    => array( category_id,special_category_id ),
                'operator' => 'AND',
            ),
        ));
    }
});

But this code is not giving me the expected result. What I am doing wrong?

发布评论

评论列表(0)

  1. 暂无评论