根据post_content,metaboxes和taxonomy搜索自定义帖子

时间:2017-09-12 10:14:43

标签: php wordpress wordpress-theming

// Start the Query

    $v_args = array(
        'post_type'     =>  'listing',
        'meta_query' => array(
                    array(
                    'key'     => 'wpcf-services',
                    'value'   => $services,
                    'compare' => 'LIKE',
                    ),
                    ),
        'tax_query' =>array(
                        'relation' => 'AND',
                array(
                        'taxonomy' => 'listing-city',
                        'field' => 'name',
                        'terms' => $location,
                        'compare' => 'LIKE',
                        'operator' => 'IN'
                ),
                array(
                        'taxonomy' => 'listing-category',
                        'field' => 'name',
                        'terms' => $listing_category,
                        'compare' => 'LIKE',
                        'operator' => 'IN'
                ),
                ),

    );

     $listingsearch = new WP_Query( $v_args );?>

此搜索适用于自定义帖子类型但我想在post_content上搜索我是如何实现此目的。

此搜索适用于自定义元和分类,但不适用于post_content

我的要求是在$ services文本框中输入值时,它将post_content和metabox(wpcf-services)中的值与OR逻辑进行比较

任何帮助?

提前致谢

1 个答案:

答案 0 :(得分:0)

尝试以下代码,如果它对您有帮助,

$v_args = array(
    'post_type'     =>  'listing',
    's' => $services_textbox,
    'meta_query' => array(
                'relation' => 'OR',
                array(
                'key'     => 'wpcf-services',
                'value'   => $services,
                'compare' => 'LIKE',
                ),
                ),
    'tax_query' =>array(
                    'relation' => 'AND',
            array(
                    'taxonomy' => 'listing-city',
                    'field' => 'name',
                    'terms' => $location,
                    'compare' => 'LIKE',
                    'operator' => 'IN'
            ),
            array(
                    'taxonomy' => 'listing-category',
                    'field' => 'name',
                    'terms' => $listing_category,
                    'compare' => 'LIKE',
                    'operator' => 'IN'
            ),
            ),

    );

    $listingsearch = new WP_Query( $v_args );