即使数据正确,wordpress元查询也总是失败

时间:2015-03-25 19:57:59

标签: php wordpress

我跟随查询 -

$query = array(
    'post_type' => 'accessory',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => 'accessory-bike',
            'value' => array("33"),
            'compare' => 'IN'
        )
    )
);

现在我在数据库中记录了这条记录 - enter image description here

520 accessory帖子类型的ID。它仍然返回0结果。我无法想象我到底在哪里做错了?愚蠢的wordpress。

SELECT   wp_posts.* 
            FROM wp_posts  
            INNER JOIN wp_postmeta 
            ON ( wp_posts.ID = wp_postmeta.post_id ) 
            WHERE 1=1  
            AND wp_posts.post_type = 'accessory' 
            AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private') 
            AND ( ( wp_postmeta.meta_key = 'accessory-bike' AND CAST(wp_postmeta.meta_value AS SIGNED) IN ('33') ) )
            GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC

1 个答案:

答案 0 :(得分:0)

520后的accessory-bike值不是33;它是一个序列化的字符串。

我可以看到你正在使用高级自定义字段,所以你需要做的就是选择一个不会在序列化字符串中保存数据的不同字段类型。您可能会发现类似自定义分类的东西更合适。