admin管理员组文章数量:1298180
I need to WP_Query
for posts which:
- either have a postmeta 'answer' set to 'yes', and whatever
post_content
; - or have 'answer' set to 'no' but only if
post_content
is empty.
So in an ideal world where performance is not an issue and where you can query both for a postmeta and post_content
, the args would look something like this:
$args = array(
'relation' => 'OR',
'meta_query' => array(
'key' => 'answer',
'compare' => '=',
'value' => 'yes'
),
array(
'relation' => 'AND',
'meta_query' => array(
'key' => 'answer',
'compare' => '=',
'value' => 'no'
),
array(
'key' => 'post_content',
'compare' => '=',
'value' => ''
)
)
);
Now, we're not in that ideal world and as far as I know I can't check the post_content
in the WP_Query
in the first place, so my answer is: which way is better to assign a post_content
related WP_Query
-able value to a post, performance wise?
- to programmatically add or remove a postmeta like 'has_content' set to 1 or 0 to the post each time it's created/updated, so I can just do a
meta_query
; - to programmatically add or remove a tag like 'has_content' set to 1 or 0 to the post each time it's created/updated (and check for it with
tag__in
inWP_Query
); - to programmatically add or remove a custom hidden taxonomy like 'has_content' set to 1 or 0 to the post each time it's created/updated (and check for it with a
tax_query
inWP_Query
); - none of the above.
I tend to exclude point 1 because I've read about meta_query
's performance issues, but I am not sure about 2-3-4.
Thanks a lot if you can help!
I need to WP_Query
for posts which:
- either have a postmeta 'answer' set to 'yes', and whatever
post_content
; - or have 'answer' set to 'no' but only if
post_content
is empty.
So in an ideal world where performance is not an issue and where you can query both for a postmeta and post_content
, the args would look something like this:
$args = array(
'relation' => 'OR',
'meta_query' => array(
'key' => 'answer',
'compare' => '=',
'value' => 'yes'
),
array(
'relation' => 'AND',
'meta_query' => array(
'key' => 'answer',
'compare' => '=',
'value' => 'no'
),
array(
'key' => 'post_content',
'compare' => '=',
'value' => ''
)
)
);
Now, we're not in that ideal world and as far as I know I can't check the post_content
in the WP_Query
in the first place, so my answer is: which way is better to assign a post_content
related WP_Query
-able value to a post, performance wise?
- to programmatically add or remove a postmeta like 'has_content' set to 1 or 0 to the post each time it's created/updated, so I can just do a
meta_query
; - to programmatically add or remove a tag like 'has_content' set to 1 or 0 to the post each time it's created/updated (and check for it with
tag__in
inWP_Query
); - to programmatically add or remove a custom hidden taxonomy like 'has_content' set to 1 or 0 to the post each time it's created/updated (and check for it with a
tax_query
inWP_Query
); - none of the above.
I tend to exclude point 1 because I've read about meta_query
's performance issues, but I am not sure about 2-3-4.
Thanks a lot if you can help!
Share Improve this question asked Oct 13, 2021 at 15:38 MarksMarks 312 bronze badges1 Answer
Reset to default 1Why would you need tag__in
for option 2? You're not searching for multiple values, only your 1 or 0. In which case, options 2 and 3 amount to the same thing behind the scenes: a taxonomy query. This way would likely be the most performant, but that said, if you don't want to mess the taxonomies, you can check for empty post content with a filter.
本文标签: wp queryWhich metaquery and postcontent blend is better in WPQueryperformance wise
版权声明:本文标题:wp query - Which meta_query and post_content blend is better in WP_Query, performance wise? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272978a2369569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论