admin管理员组文章数量:1023848
I'm currently building my own backlog tracker and have gotten to a point where I just have no idea how I'm going to do this.
I have multiple status categories (for example; beaten and completed) and categories for the consoles (for example PS4 and Nintendo Switch). Now I want to display how many games(posts) I have beaten (Category A) for the Nintendo Switch (Category B)
For Example; I have 66 games, 34 from those are from the Nintendo Switch. From those 34 Switch games, I have actually beaten 24. I want to display this "24".
can anyone give me an idea of where to go and how to fix this problem?
I'm currently building my own backlog tracker and have gotten to a point where I just have no idea how I'm going to do this.
I have multiple status categories (for example; beaten and completed) and categories for the consoles (for example PS4 and Nintendo Switch). Now I want to display how many games(posts) I have beaten (Category A) for the Nintendo Switch (Category B)
For Example; I have 66 games, 34 from those are from the Nintendo Switch. From those 34 Switch games, I have actually beaten 24. I want to display this "24".
can anyone give me an idea of where to go and how to fix this problem?
Share Improve this question edited Apr 23, 2019 at 23:04 Nicolai Grossherr 18.9k8 gold badges64 silver badges109 bronze badges asked Apr 23, 2019 at 21:49 MiiaruMiiaru 311 bronze badge1 Answer
Reset to default 2Make use of the WP_Query
class, namely the tax_query
and fields
parameters. Get the count from the $found_posts
property. Please note, this is exemplary code.
$query = new WP_Query( [
'post_type' => 'games',
'tax_query' = [
'relation' => 'AND',
[
'taxonomy' => 'game_status',
'field' => 'slug',
'terms' => [ 'beaten' ],
],
[
'taxonomy' => 'console',
'field' => 'slug',
'terms' => [ 'switch' ],
]
],
'fields' => 'ids',
] );
$count = $query->found_posts;
I'm currently building my own backlog tracker and have gotten to a point where I just have no idea how I'm going to do this.
I have multiple status categories (for example; beaten and completed) and categories for the consoles (for example PS4 and Nintendo Switch). Now I want to display how many games(posts) I have beaten (Category A) for the Nintendo Switch (Category B)
For Example; I have 66 games, 34 from those are from the Nintendo Switch. From those 34 Switch games, I have actually beaten 24. I want to display this "24".
can anyone give me an idea of where to go and how to fix this problem?
I'm currently building my own backlog tracker and have gotten to a point where I just have no idea how I'm going to do this.
I have multiple status categories (for example; beaten and completed) and categories for the consoles (for example PS4 and Nintendo Switch). Now I want to display how many games(posts) I have beaten (Category A) for the Nintendo Switch (Category B)
For Example; I have 66 games, 34 from those are from the Nintendo Switch. From those 34 Switch games, I have actually beaten 24. I want to display this "24".
can anyone give me an idea of where to go and how to fix this problem?
Share Improve this question edited Apr 23, 2019 at 23:04 Nicolai Grossherr 18.9k8 gold badges64 silver badges109 bronze badges asked Apr 23, 2019 at 21:49 MiiaruMiiaru 311 bronze badge1 Answer
Reset to default 2Make use of the WP_Query
class, namely the tax_query
and fields
parameters. Get the count from the $found_posts
property. Please note, this is exemplary code.
$query = new WP_Query( [
'post_type' => 'games',
'tax_query' = [
'relation' => 'AND',
[
'taxonomy' => 'game_status',
'field' => 'slug',
'terms' => [ 'beaten' ],
],
[
'taxonomy' => 'console',
'field' => 'slug',
'terms' => [ 'switch' ],
]
],
'fields' => 'ids',
] );
$count = $query->found_posts;
本文标签: wp queryCounting number of posts with Category B in Category A
版权声明:本文标题:wp query - Counting number of posts with Category B in Category A 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745561052a2156164.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论