dongzh1988 2018-08-09 07:26
浏览 45

Wordpress自定义字段搜索忽略关系'和'

I am trying to query products by a category and a custom field called 'gender'. The condition output in sql always is using "OR" instead of "AND" for the gender search.

add_filter('get_meta_sql', 'filter_query', 10, 1);
$product_dis = new WP_Query(array(
'post_type'      => 'product',
'post_status'    => 'publish',
'posts_per_page' => -1,
'relation'=>'AND',
'tax_query'      => array(
    'relation'=>'AND',
    array(
         'relation'=>'AND',
        'taxonomy'   => 'product_category',
        'field'      => 'term_id',
        'terms'      => array($category_id, $subcat_id)
    ), ),
'meta_query'    => array(
    'relation'=>'AND',
    array(
        'relation'=>'AND',
        'key'     => 'gender',
        'value'   => $gender,
        'compare' => '=',
    ),),
) );

OUTPUT

SELECT kh_posts.* FROM kh_posts LEFT JOIN kh_term_relationships ON (kh_posts.ID = kh_term_relationships.object_id) INNER JOIN kh_postmeta ON ( kh_posts.ID = kh_postmeta.post_id ) WHERE 1=1 AND (kh_term_relationships.term_taxonomy_id IN (10,19,21) ) OR ( ( kh_postmeta.meta_key = 'gender' AND kh_postmeta.meta_value = 'male' ) ) AND kh_posts.post_type = 'product' AND ((kh_posts.post_status = 'publish')) GROUP BY kh_posts.ID ORDER BY kh_posts.menu_order ASC

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比