Try this
/**
* 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();
}
Use short-code like:
[listing type=”YOUR CUSTOM POST TYPE HERE”]
Please try and let me know if any query
Thanks!