gpt4 book ai didi

php - 由元查询引起的 WordPress 查询速度非常慢

转载 作者:行者123 更新时间:2023-11-29 07:48:48 25 4
gpt4 key购买 nike

我试图在幻灯片中添加基于 2 个不同键的 2 种类型的幻灯片,只是元查询非常慢。我正在使用的 WordPress 查询是:

$args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sgt_slide',
'value' => 'on',
'compare' => '='
),
array(
'key' => 'sgt_slide_home',
'value' => 'on',
'compare' => '='
)
),
'no_found_rows' => true, //exclude unnecessary paging calculations
'numberposts' => -1,
'post_status' => array( 'publish', 'inherit' ),
'post_type' => array( 'post', 'attachment' )
);
$slides = get_posts($args);

结果是sql匹配查询

SELECT   nd_posts.* FROM nd_posts  INNER JOIN nd_postmeta ON (nd_posts.ID = nd_postmeta.post_id)
INNER JOIN nd_postmeta AS mt1 ON (nd_posts.ID = mt1.post_id) WHERE 1=1 AND nd_posts.post_type IN ('post', 'attachment') AND ((nd_posts.post_status = 'publish' OR nd_posts.post_status = 'inherit')) AND ( (nd_postmeta.meta_key = 'sgt_slide' AND CAST(nd_postmeta.meta_value AS CHAR) = 'on')
OR (mt1.meta_key = 'sgt_slide_home' AND CAST(mt1.meta_value AS CHAR) = 'on') ) GROUP BY nd_posts.ID ORDER BY nd_posts.post_date DESC

此 SQL 在 7 秒内完成查询加载,在 phpmyadmin 中进行了测试。我该如何克服这个问题。

解释 SQL

explain sql

最佳答案

尝试添加'cache_results' => false,到你的循环

关于php - 由元查询引起的 WordPress 查询速度非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26991317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com