douche3244 2017-07-07 13:04
浏览 39
已采纳

当meta_key的值是数组时,如何进行meta_query?

I am working on Wordpress website and hit an obstacle when I tried to do the following query:

    $args=array(
     'post_type' => 'post',
     'post_status' => 'publish',
     'meta_query'    =>  array(
        array(
       'key'     => 'ad_info', 
        'value'  => // check again with weight between 50 and 100,
        'compare' => //compare operator, 
        ),      
       )
     );

the value of the key ad_info is: Array ( [weight] => 48 [height] => 160) and I want to check if the value of weight in this array is between 50 and 100. Can anybody help me on this problem? Thanks

  • 写回答

1条回答 默认 最新

  • drnvcm3949 2017-07-07 14:15
    关注

    In mysql array values saved as strings, and it make problem for WP_Query filtering.

    So best solution in this problem - change saving method to 2 keys:

    ad_info_width and ad_info_height.

    In that way you can use meta_query between compare.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有卷积神经网络识别害虫的项目吗
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件