试试这个
/**
* Register all shortcodes
*
* @return null
*/
function register_shortcodes() {
add_shortcode( \'listing\', \'shortcode_mostra_produtos\' );
}
add_action( \'init\', \'register_shortcodes\' );
/**
* Produtos Shortcode Callback
*
* @param Array $atts
*
* @return string
*/
function shortcode_mostra_produtos( $atts ) {
global $wp_query,
$post;
$atts = shortcode_atts( array(
\'type\' => \'\'
), $atts );
$loop = new WP_Query( array(
\'posts_per_page\' => \'-1\',
\'post_type\' => $atts[\'type\']
) );
if( ! $loop->have_posts() ) {
return false;
}
while( $loop->have_posts() ) {
$loop->the_post();
echo the_title();
// DO YOUR HTML STUFF HERE
}
wp_reset_postdata();
}
使用短代码,如:
[列表类型=“此处为您的自定义帖子类型”]
如果有任何疑问,请尝试让我知道
谢谢