-1

I am New To Wordpress Plugin Development. I want to Create Short Code using Custom Post Type Method

function baztag_func( $atts, $content = "" ) {
    return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
  • Sorry! But not getting you. What exactly want you ? – Pratik Patel Oct 26 '18 at 6:09
  • [contact-form-7 id="11" title="Contact form 1"] – Ragupathi Oct 26 '18 at 6:28
  • create short code like this – Ragupathi Oct 26 '18 at 6:28
  • but i want use cusome post type – Ragupathi Oct 26 '18 at 6:29
  • You want custom post type posts listing ,using shortcode right ? – Pratik Patel Oct 26 '18 at 6:30
1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.