[英]I get null from a SQL query in WordPress
I have a problem trying to get data from a specific meta_value in WordPress, that is, when I do a " WHERE AND (PM.meta_key= 'webm' and PM.meta_value= 'Chaturbate')
" in the sql query.我在尝试从 WordPress 中的特定元值获取数据时遇到问题,也就是说,当我在 sql 查询中执行“
WHERE AND (PM.meta_key= 'webm' and PM.meta_value= 'Chaturbate')
”时。 When I don't use where and get all the data it usually looks like this:当我不使用 where 并获取所有数据时,它通常如下所示:
SELECT P.ID,
MAX(CASE WHEN PM.meta_key = 'nombrem' THEN PM.meta_value END) AS nombrem,
MAX(CASE WHEN PM.meta_key = 'generom' THEN PM.meta_value END) AS generom,
MAX(CASE WHEN PM.meta_key = 'tiempom' THEN PM.meta_value END) AS tiempom,
MAX(CASE WHEN PM.meta_key = 'urlm' THEN PM.meta_value END) AS urlm,
MAX(CASE WHEN PM.meta_key = 'imagenm' THEN PM.meta_value END) AS imagenm
FROM
K1nG_posts AS P
LEFT JOIN K1nG_postmeta AS PM ON P.ID = PM.post_id
WHERE
P.post_type = 'post'
AND (P.post_status = 'publish' OR P.post_status = 'private')
GROUP BY P.ID, P.post_date
But when I use the " WHERE AND (PM.meta_key= 'webm' and PM.meta_value= 'Chaturbate')
" in a meta_value of a respective meta_key called "webm", I get the matching records but without the "select" information, that is, null, as can be seen in the image:但是,当我在名为“webm”的相应 meta_key 的 meta_value 中使用“
WHERE AND (PM.meta_key= 'webm' and PM.meta_value= 'Chaturbate')
”时,我得到了匹配记录但没有“select”信息,即null,如图所示:
SELECT P.ID,
MAX(CASE WHEN PM.meta_key = 'nombrem' THEN PM.meta_value END) AS nombrem,
MAX(CASE WHEN PM.meta_key = 'generom' THEN PM.meta_value END) AS generom,
MAX(CASE WHEN PM.meta_key = 'tiempom' THEN PM.meta_value END) AS tiempom,
MAX(CASE WHEN PM.meta_key = 'urlm' THEN PM.meta_value END) AS urlm,
MAX(CASE WHEN PM.meta_key = 'imagenm' THEN PM.meta_value END) AS imagenm
FROM
K1nG_posts AS P
LEFT JOIN K1nG_postmeta AS PM ON P.ID = PM.post_id
WHERE
P.post_type = 'post'
AND (P.post_status = 'publish' OR P.post_status = 'private')
AND (PM.meta_key= 'webm' and PM.meta_value= 'Chaturbate')
GROUP BY P.ID, P.post_date
try to use this code尝试使用此代码
WHERE
P.post_type = 'post'
AND P.post_status = 'publish' OR P.post_type = 'post' AND P.post_status = 'private'
this basically takes这基本上需要
P.post_type = 'post' AND P.post_status
as A and作为 A 和
P.post_type = 'post' AND P.post_status = 'private'
as B so it is就像B一样
A or B
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.