gpt4 book ai didi

mysql - 单个查询中的多个元键和元值(wordpress)

转载 作者:行者123 更新时间:2023-11-30 23:10:08 26 4
gpt4 key购买 nike

我在 wordpress 中成功运行查询。查询如下。

SELECT wp_posts.*, wp_postmeta.meta_value
FROM wp_posts, wp_postmeta, wp_term_relationships, wp_terms
WHERE term_id = '12'
AND term_taxonomy_id = '12'
AND ID = post_id
AND ID = object_id
AND post_type = 'property'
AND post_status = 'publish'
AND meta_key = 'property_amount'
AND replace(replace(meta_value, ',', ''), '"', '') >= 1
GROUP BY wp_posts.ID
ORDER BY replace(replace(meta_value, ',', ''), '"', '') DESC LIMIT 0, 10

但我想在上面的查询中再添加一个 meta_key 及其值条件,所以我将查询更改为此

SELECT wp_posts.*, wp_postmeta.meta_value
FROM wp_posts, wp_postmeta, wp_term_relationships, wp_terms
WHERE term_id = '12'
AND term_taxonomy_id = '12'
AND ID = post_id
AND ID = object_id
AND post_type = 'property'
AND post_status = 'publish'
AND ((wp_postmeta.meta_key = 'property_amount'
AND wp_postmeta.meta_value) >= '1'
AND (wp_postmeta.meta_key = 'property_land_type'
AND wp_postmeta.meta_value IN ('H', 'C')))
GROUP BY wp_posts.ID

下一行在第一个查询中是多余的

meta_key="property_land_type" and meta_value in ('L','H','C')

但它不起作用。如何做到这一点。这次我不能写 WP_Query,因为我有很多基于此查询的其他查询。

提前致谢!!!

最佳答案

在不添加自己的查询的情况下,尝试扩展 wordpress 查询。您可以自定义以下代码,

$args = array(
'post_type' => 'property',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'property_amount',
'value' => '1',
'compare' => 'LIKE',
),
array(
'key' => 'property_land_type',
'value' => 'L',
'compare' => 'LIKE',
)
)
);

$query = new WP_Query( $args );

关于mysql - 单个查询中的多个元键和元值(wordpress),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20162485/

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