admin管理员组文章数量:1130349
In a RDMS with the following query I try to get postmeta.meta_value of the post with custom post type points. To identify which key they belong to I made a case when. This query returns a greater number of records than the number of custom post types in most cases full of null. What I expect is a result that contains the same number of custom post type points. Could you please tell me the correct way to do this?
SELECT
case when wp_postmeta.meta_key = 'zone' then wp_postmeta.meta_value end 'zone',
case when wp_postmeta.meta_key = 'category' then wp_postmeta.meta_value end 'category',
case when wp_postmeta.meta_key = 'country' then wp_postmeta.meta_value end 'country'
FROM
wp_posts
INNER JOIN
wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE
wp_posts.post_type = 'points'
I hope a result that can look like this
+----------------------------------+---------+------------------------+
| zone | cate | country |
+----------------------------------+---------+------------------------+
| Zone 1 | Cat 1 | Country 1 |
| Zone 2 | Cat 2 | Country 2 |
| Zone 1 | Cat 3 | Country 3 |
+----------------------------------+---------+------------------------+
I do not know if this is relevante but this postmeta key/values area created by custom fields created by Advanced custom fields plugin
In a RDMS with the following query I try to get postmeta.meta_value of the post with custom post type points. To identify which key they belong to I made a case when. This query returns a greater number of records than the number of custom post types in most cases full of null. What I expect is a result that contains the same number of custom post type points. Could you please tell me the correct way to do this?
SELECT
case when wp_postmeta.meta_key = 'zone' then wp_postmeta.meta_value end 'zone',
case when wp_postmeta.meta_key = 'category' then wp_postmeta.meta_value end 'category',
case when wp_postmeta.meta_key = 'country' then wp_postmeta.meta_value end 'country'
FROM
wp_posts
INNER JOIN
wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE
wp_posts.post_type = 'points'
I hope a result that can look like this
+----------------------------------+---------+------------------------+
| zone | cate | country |
+----------------------------------+---------+------------------------+
| Zone 1 | Cat 1 | Country 1 |
| Zone 2 | Cat 2 | Country 2 |
| Zone 1 | Cat 3 | Country 3 |
+----------------------------------+---------+------------------------+
I do not know if this is relevante but this postmeta key/values area created by custom fields created by Advanced custom fields plugin
本文标签: How to properly get the wppostmetametavalue of a custom post type in specifics
版权声明:本文标题:How to properly get the wp_postmeta.meta_value of a custom post type in specifics? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749126523a2319871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论