wordpress多自定义分类法查询

$args = array(
            'orderby' => 'date',
            'order' => 'DESC',
            'offset'=>0,//分页,从0开始,我们习惯从1开始,这里可以根据情况兼容。
            'showposts' => 10,//分页大小
            'post_type' => 'course',
            'post_status' => 'publish',
            'tax_query' => array(//分类法参数数组
                array(
                    'taxonomy' => 'course_cat',
                    'field'    => 'id',//这里可以使用slug,就需要提供term的别名。
                    'terms'    => array(39)
                ),
                array(
                    'taxonomy' => 'course_author',
                    'field'    => 'id',
                    'terms'    => array(21)
                )
            )
        );

也可以通过自定义字段查询,如下

$args = array(
    'post_type'  => 'product',
    'meta_query' => array(
        array(
            'key'   => 'featured',
            'value' => 'yes',
        )
    )
);
$postslist = get_posts( $args );

官网说明
Show posts associated with a certain custom field. Following example displays posts from the ‘product’ post type that have meta key ‘featured’ with value ‘yes’, using ‘meta_query’

暂无评论

相关推荐

微信扫一扫,分享到朋友圈

wordpress多自定义分类法查询