我正在构建一个快捷码,它将显示我的自定义帖子类型(公文包)。我想添加另一个选项来添加要显示的项目数。这是我现在拥有的,但它显示了所有项目,我需要添加一个“items”shortcode\\u att,但不确定以后如何在查询中调用它。非常感谢。
add_shortcode( \'type_portfolio\', function( $atts, $content = null ){
$atts = shortcode_atts(
array(
\'column\' => \'3\',
\'category\' => \'0\'
), $atts);
extract($atts);
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'fen_portfolio\'
);
if( $category > \'0\' ){
$args[\'tax_query\'] = array(
array(
\'posts_per_page\' => -1,
\'taxonomy\' => \'cat_portfolio\',
\'field\' => \'term_id\',
\'terms\' => $category
)
);
}
$portfolios = get_posts( $args );
最合适的回答,由SO网友:D. Dan 整理而成
add_shortcode( \'type_portfolio\', function( $atts, $content = null ){
$atts = shortcode_atts(
array(
\'column\' => \'3\',
\'category\' => \'0\',
\'ppp\' => -1
), $atts);
extract($atts);
$args = array(
\'posts_per_page\' => $ppp,
\'post_type\' => \'fen_portfolio\'
);
if( $category > \'0\' ){
$args[\'tax_query\'] = array(
array(
\'posts_per_page\' => -1,
\'taxonomy\' => \'cat_portfolio\',
\'field\' => \'term_id\',
\'terms\' => $category
)
);
}
$portfolios = get_posts( $args );