$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to properly get the wp_postmeta.meta_value of a custom post type in specifics?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to properly get the wp_postmeta.meta_value of a custom post type in specifics?

matteradmin9PV0评论

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

Post a comment

comment list (0)

  1. No comments so far