多个meta\u查询mysql挂起

t3psigkw  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(272)

我使用wp\u查询我有很多参数要比较,所以我必须使用多个meta\u查询(12)
查询将创建一个包含至少12个内部联接的大型sql语句
这种行为使mysql服务器挂起(即使表非常小)
有解决办法吗?
除了用php过滤结果之外?

Array
(
    [post_type] => financing
    [posts_per_page] => 20
    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => family_status
                    [value] => "נשוי"
                    [compare] => LIKE
                )

            [1] => Array
                (
                    [key] => has_appartment
                    [value] => 1
                    [compare] => =
                )

            [2] => Array
                (
                    [key] => gender
                    [value] => "זכר"
                    [compare] => LIKE
                )

            [3] => Array
                (
                    [key] => occupational_status
                    [value] => "שכיר"
                    [compare] => LIKE
                )

            [4] => Array
                (
                    [key] => min_in_bank_stage
                    [value] => 1
                    [compare] => <=
                    [type] => NUMERIC
                )

            [5] => Array
                (
                    [key] => max_children
                    [value] => 2
                    [compare] => >=
                    [type] => NUMERIC
                )

            [6] => Array
                (
                    [key] => minimum_monthly_income
                    [value] => 12222
                    [compare] => <=
                    [type] => NUMERIC
                )

            [7] => Array
                (
                    [key] => min_age
                    [value] => 3
                    [compare] => <=
                    [type] => NUMERIC
                )

            [8] => Array
                (
                    [key] => max_age
                    [value] => 3
                    [compare] => >=
                    [type] => NUMERIC
                )

            [9] => Array
                (
                    [key] => mortgage_payment_min
                    [value] => 1222
                    [compare] => <=
                    [type] => NUMERIC
                )

            [10] => Array
                (
                    [key] => mortgage_payment_max
                    [value] => 1222
                    [compare] => >=
                    [type] => NUMERIC
                )

            [11] => Array
                (
                    [key] => other_payments_amount_min
                    [value] => 111
                    [compare] => <=
                    [type] => NUMERIC
                )

            [12] => Array
                (
                    [key] => other_payments_amount_max
                    [value] => 111
                    [compare] => >=
                    [type] => NUMERIC
                )

        )

)
xmjla07d

xmjla07d1#

根据你发帖的结果,我给你举了一个例子。所以,你可以试试这个代码,

<?php
$args = array(
    'post_type'  => 'financing',
    'posts_per_page' => '20',
    'meta_query' => array(
       'relation' => 'OR',
        array(
            'key'     => 'family_status',
            'value'   => 'נשוי',            
            'compare' => 'LIKE'
        ),
        array(
            'key'     => 'has_appartment',
            'value'   => '1',
            'compare' => 'EQUAL'
        ),
        array(
            'key'     => 'gender',
            'value'   => 'זכר',
            'compare' => 'LIKE'
        ),
        continue added more array as per example....        
    )
);
$search_query = new WP_Query( $args );
$min_max_values = array();
if ( $search_query->have_posts() ) {
    while( $search_query->have_posts() ) {
        $search_query->the_post();
        array_push( $min_max_values, get_the_ID() );
    }
}
wp_reset_postdata();
?>

希望你明白!!

相关问题