Sql wordpress中meta与tax查询的关系

Sql wordpress中meta与tax查询的关系,sql,wordpress,meta,tax,Sql,Wordpress,Meta,Tax,我的WordPress查询有问题。我知道我不能在WP查询中设置税务查询和元查询之间的关系,所以我必须编写自定义SQL查询 我需要显示的职位有类别从数组类别或有相同的值从自定义字段 我的代码: global $wpdb; global $post; $categories = get_the_category(); $locations = get_field('connect_post_to_a_location'); $location_array = []; $category_array

我的WordPress查询有问题。我知道我不能在WP查询中设置税务查询和元查询之间的关系,所以我必须编写自定义SQL查询

我需要显示的职位有类别从数组类别或有相同的值从自定义字段

我的代码:

global $wpdb;
global $post;
$categories = get_the_category();
$locations = get_field('connect_post_to_a_location');
$location_array = [];
$category_array = [];
if (!empty( $categories )) :
    foreach($categories as $category):
        $category_array[]=$category->term_id;
    endforeach;
endif;

if( !empty($locations) ):
    foreach( $locations as $location ):
        $location_array[] = $location;
    endforeach;
endif;
下面是wp查询,但它不起作用,因为我无法设置税务查询和元查询之间的关系

$args = (
    array (
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'post__not_in' => array($id),
        'orderby'        => 'date',
        'order'          => 'DESC',

    )
);

if(!empty($category_array)) {
    $args['tax_query'] =  array(
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    => $category_array
        )
    );
}

if ( !empty($location_array) ) {
    $meta_arr = array(
        'relation' => 'OR',
    );
    foreach($location_array as $value){
        $meta_arr[] = array(
            'key' => 'connect_post_to_a_location',
            'value' => serialize(strval($value)),
            'compare' => 'LIKE',
        );
    }
    $args['meta_query'] = $meta_arr;
}


现在我必须将我的WP查询转换为自定义查询,但我不知道如何才能做到这一点。我写了唯一一个简单的查询,它可以工作,但我需要添加税和元查询,所以请给我任何建议或例子。谢谢

global $wpdb;
global $post;

$querystr = "
    SELECT $wpdb->posts.*
    FROM $wpdb->posts
    WHERE $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    ORDER BY $wpdb->posts.post_date DESC
";

$pageposts = $wpdb->get_results($querystr, OBJECT);

if ($pageposts):
    foreach ($pageposts as $post):
        setup_postdata($post);
?>
        <div>
        //some code
        </div>
<?php
    endforeach;
endif;`enter code here`

global$wpdb;
全球$员额;
$querystr=”
选择$wpdb->posts*
从$wpdb->posts
其中$wpdb->posts.post_status='publish'
和$wpdb->posts.post_type='post'
按$wpdb->posts.post\u日期描述订购
";
$pageposts=$wpdb->get_结果($querystr,OBJECT);
如果($pageposts):
foreach($pageposts作为$post):
设置_postdata($post);
?>
//一些代码