我有一个快捷码,试图从$args
下面的数组。
查询:
$args = array(
//\'post_type\' => $posttype,
\'post_type\' => explode( \', \', $posttype ),
);
$myquery = new WP_Query( $args );
有条件的:if ( $posttype == \'cpt_press\' ) :
the_content();
else :
the_excerpt();
endif;
短代码:[myquery posttype=\'cpt_press\']
在上面的条件中,我能够检索所有具有post类型的帖子\'cpt_press\'
如果I don\'t use explode. 我使用explode的原因是为了能够做到这一点:[myquery posttype=\'cpt_press, cpt_two, cpt_three, cpt_etc\']
有什么帮助吗?更新的代码块
function myshortcode( $params, $content = null ) {
global $post;
extract( shortcode_atts( array(
\'posttype\' => \'\',
\'meta_key\' => \'\',
\'priority\' => \'\',
\'meta_compare\' => \'\',
\'layout\' => \'rows\',
\'cols\' => 1,
\'tag\' => \'\',
\'count\' => 10,
\'orderby\' => \'date\',
\'order\' => \'DESC\'
), $params ) );
$args = array(
\'post_type\' => explode( \',\', $posttype ),
);
$myquery = new WP_Query( $args );
ob_start();
?><div class="row"><?php
// The Loop
if ( $myquery->have_posts() ) : while( $myquery->have_posts() ) : $myquery->the_post();
if ( $posttype == \'cpt_press\' ) :
the_content();
else :
the_excerpt();
endif;
endwhile;
endif;
wp_reset_postdata();
?></div><?php
return ob_get_clean();
}
add_shortcode( \'myquery\', \'myshortcode\' );