WP,传递几个id来查询

时间:2017-09-08 13:55:22

标签: php wordpress

function my_relationship_query( $args, $field, $post_id ) {

// only show children of the current post being edited
$args['post_parent'] = $post_id;


// return
return $args;

}

例如,我可以将两个参数作为post_id传递?这样做的唯一方法包括编写一些元查询吗?

1 个答案:

答案 0 :(得分:2)

根据WP_Query将一系列帖子ID传递给post_parent__in(假设$args代表WP_Query参数):

$post_id_array = array( $id1, $id2 );

function my_relationship_query( $args, $field, $post_id_array ) {

    // only show children of the current post being edited
    $args['post_parent__in'] = $post_id_array;

    // return
    return $args;
}