我试图制作一个可以在WordPress中检查两个类别的插件

发布于 2025-02-09 08:19:22 字数 1257 浏览 0 评论 0原文

我正在尝试制作一个可以在WordPress中检查两个类别的插件。

我想在这样的页面上有快捷代码:

[CAT_COUNT_MULTI category =“ JP- evest+jp- 1月”]

Plugin Name: Count Posts
Plugin URI: http://a4jp.com/plugins/
Description: Adds a custom short code that returns the number of posts.
Version: 1.0 altered
License: GPLv2 

*/



    function cat_count_multi( $atts ) {
    
function my_post_count($tax, $cat1, $cat2) {
    $args = array(
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => $tax,
                'field' => 'term_taxonomy_id',
                'terms' => array( $cat1 ),
                'operator' => 'IN'
            ),
            array(
                'taxonomy' => $tax,
                'field' => 'term_taxonomy_id',
                'terms' => array( $cat2 ),
                'operator' => 'IN'
            ),
        )
    );
    $query = new WP_Query( $args );
    return $query->post_count;
}
echo my_post_count('translates_category', 220, 238);
}

add_shortcode( 'cat_count_multi', 'cat_count_multi' );

我需要做什么来解决此问题以使其有效?我认为这很接近。 我不想添加页面的数量,但要获得

<?php echo($ wp_query-> stud_posts)?>

结果。

I'm trying to make a plugin that can check two categories in Wordpress.

I want to have shortcode on pages like this:

[cat_count_multi category="jp-events+jp-1月"]

Plugin Name: Count Posts
Plugin URI: http://a4jp.com/plugins/
Description: Adds a custom short code that returns the number of posts.
Version: 1.0 altered
License: GPLv2 

*/



    function cat_count_multi( $atts ) {
    
function my_post_count($tax, $cat1, $cat2) {
    $args = array(
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => $tax,
                'field' => 'term_taxonomy_id',
                'terms' => array( $cat1 ),
                'operator' => 'IN'
            ),
            array(
                'taxonomy' => $tax,
                'field' => 'term_taxonomy_id',
                'terms' => array( $cat2 ),
                'operator' => 'IN'
            ),
        )
    );
    $query = new WP_Query( $args );
    return $query->post_count;
}
echo my_post_count('translates_category', 220, 238);
}

add_shortcode( 'cat_count_multi', 'cat_count_multi' );

What do I need to do to fix this so it works? I think it is very close.
I don't want to add the number of the pages but get the

<?php echo ($wp_query->found_posts) ?>

result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文