简体   繁体   English

如何通过meta_value和meta_key检索meta_values的结果?

[英]How to retrieve results of meta_values by meta_value and meta_key?

I'm trying to SELECT all the meta values from my WP database where meta_value = 'x' and meta_key = 'y'. 我正在尝试从WP数据库中选择所有meta值,其中meta_value ='x'和meta_key ='y'。 But my query returns nothing: 但是我的查询什么都不返回:

SELECT meta_value FROM `tst_postmeta` WHERE meta_key = 'thevoters' AND meta_value = 'mint'

What am I doing wrong here?! 我在这里做错了什么?

Update 更新资料

The query should return the meta_value column with some ids based on meta_key called 'the_voters' but also where meta_value equals 'mint'. 查询应返回meta_value列,其中包含基于meta_key称为“ the_voters”的一些ID,但meta_value等于“ mint”的情况。

I've also tried this query: 我也尝试过以下查询:

SELECT meta_value FROM `tst_postmeta` WHERE meta_key = 'thevoters' AND meta_key = 'sticker_chosen' AND meta_value = 'mint'

From the little information you offered and your query my guess is that no data exists for your query. 从您提供的少量信息和查询中,我的猜测是查询没有数据。

Have you tried seeing what shows up when you run 您是否尝试查看运行时显示的内容

SELECT * 
FROM tst_postmeta

This should show you everything in your table and you can filter by meta key and meta value in your result to see if anything exists for those values. 这应该向您显示表中的所有内容,并且您可以按结果中的meta键和meta值进行过滤,以查看这些值是否存在任何内容。

You can also try breaking down your query into two queries to see if either provides a result, if nothing shows up for either query then there will be no values when you combine them. 您也可以尝试将查询细分为两个查询,以查看其中一个是否提供结果,如果两个查询均未显示任何结果,则将它们组合在一起将没有任何值。

SELECT meta_value 
FROM tst_postmeta 
WHERE meta_key = 'thevoters' 

SELECT meta_value 
FROM tst_postmeta 
WHERE meta_value = 'mint'

您的SQL是正确的,但结果集中没有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过meta_key和meta_values数组获取用户 - Get users by meta_key and array of meta_values WPDB查询-根据_meta_key返回meta_value - WPDB Query - Return meta_value based on _meta_key 构造MySQL查询(meta_key / meta_value表) - Construct MySQL query ( meta_key/meta_value table) 通过在Wordpress中由meta_key和meta_value标识的自定义查询字符串来检索发布 - Retrieve Post by Custom Query String identified by meta_key and meta_value in Wordpress 如果WordPress中的meta_key = x和meta_value = y,如何显示图像? - How can I display an image if the meta_key=x AND meta_value=y in WordPress? 如何保存和获取特定页面的注释meta_key和meta_value - how to save and get comment meta_key and meta_value for specific page 如何计算某个meta_key在列中出现meta_value的次数? - How to count how many times a meta_value appears in a column by certain meta_key? 带有多个meta_values的wordpress WP_Query meta_key - Wordpress WP_Query with multiple meta_values for a meta_key 我有查询来检索wordpress中的所有帖子,但是如何检查发布条件meta_key =“ develop”和meta_value ='anything' - I have query to retrieve all posts in wordpress but how can i check the condition for post meta_key =“develop” and meta_value='anything' 按meta_key值对搜索结果进行排序 - Sort search results by meta_key value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM