So I have 2 custom fields that I'm querying. The first, 'feature' is a true/false field and video_id is a text input field (which is hidden until another field that has a condition to show it). I basically want to get all posts where feature is false and video_id doesn't exist. I have a solution that works but it takes around 30seconds to execute which is too long:
$newsArgs = array(
'post_type' => 'post',
'posts_per_page' => $newsLen,
'post__in' => $stickies,
'tax_query' => array(
'relation' => 'AND',
$user->getTaxQuery('all')
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'video_id',
'compare' => 'NOT EXISTS'
),
array(
'relation' => 'OR',
array(
'key' => 'feature',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'feature',
'value' => '1',
'compare' => '!='
)
)
)
);
Looking at the wordpress documentation I tried this based on what I understood from it, however this did not work for me:
$newsArgs = array(
'post_type' => 'post',
'posts_per_page' => $newsLen,
'post__in' => $stickies,
'tax_query' => array(
'relation' => 'AND',
$user->getTaxQuery('all')
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'video_id',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'feature',
'value' => '1',
'compare' => '!='
)
)
);
Also if I just try querying all posts with no video_id but including feature and the other way round, all posts with video_id but no feature. The query works and is instant. Is there something I'm doing wrong here, is there anyway I can help improve the performance? Any help would be much appriciated. I'm also tryng to avoid writing a mySQL query as the $user->getTaxQuery I have under tax_query would be a ball ache. Thanks in advance
question from:
https://stackoverflow.com/questions/65829894/wordpress-meta-query-slow-loading 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…