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. When I don't use where and get all the data it usually looks like this:
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:
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
P.post_type = 'post' AND P.post_status = 'private'
as B so it is
A or B
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.