meta_query, how to search using both relation OR & AND?

前端 未结 2 1396
孤城傲影
孤城傲影 2021-02-01 03:28

Resolved: See answer below.


I have a custom post type called BOOKS. It has several custom fields, named: TITLE, AUTHOR, GE

2条回答
  •  离开以前
    2021-02-01 03:55

    I found the solution with some help. The code below worked perfectly.

        $args => array(
            'relation' => 'AND',
            array(
                'relation' => 'OR',
                array(
                    'key' => 'title',
                    'value' => $searchvalue,
                    'compare' => 'LIKE'
                ),
                array(
                    'key' => 'author',
                    'value' => $searchvalue,
                    'compare' => 'LIKE'
                ),
                array(
                    'key' => 'genre',
                    'value' => $searchvalue,
                    'compare' => 'LIKE'
                )
            ),
            array(
                'key' => 'rating',
                'value' => $ratingvalue,
                'compare' => '=',
                'type' => 'NUMERIC'
    
            )
        )
    );
    

提交回复
热议问题