当我在类别 id 中传递数组时它可以工作但是当我传递 php 变量时它不会工作

When i pass array in category id it works but when i pass php variable it will not works

我想获取 posts 的自定义 post tpye 当我在查询中直接传递 cat id 时它对我来说工作正常给出所有类别 id 的 posts 但是当我将这些类别 ID 传递到 $catid = array(154,153,155) 之类的变量中; 然后传递这个 $cat id 它不会工作

global $wpdb;
    global $posts;
    $catId = $args['categoryid'];
    $perPage = $args['post_per_page'];
    print_r($catId);
    $posts_array = get_posts(
    array(
        'posts_per_page' => $perPage,
        'post_type' => 'blog',
        'tax_query' => array(
            array(
                'taxonomy' => 'blog_cat',
                'field' => 'term_id',
                'terms' => array($catId)

            )
        )
    )
);
    echo '<pre>';
    print_r($posts_array);

分解$args['categoryid']中逗号分隔的字符串得到一个数组,然后传递给下面的函数

global $wpdb;
global $posts;
$catId = explode(',',$args['categoryid']);
$perPage = $args['post_per_page'];

$posts_array = get_posts(
    array(
        'posts_per_page' => $perPage,
        'post_type' => 'blog',
        'tax_query' => array(
            array(
                'taxonomy' => 'blog_cat',
                'field' => 'term_id',
                'terms' => $catId,
                'operator' => 'IN'

            )
        )
    )
);
echo '<pre>';
print_r($posts_array);