我试图制作一个可以在WordPress中检查两个类别的插件
我正在尝试制作一个可以在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论