Shortcode inside custom post wordpress

Shortcode inside custom post wordpress

Sharing is caring!

We are using the php code for custom post list show shortcode. You can use the code for your next post list show shortcode. That is very easy code , I hope that you are understand which function i am using. Just double click on the code syntex.

function post_shortcode($atts){
    extract( shortcode_atts( array(
        'count' => '',
    ), $atts) );
    $q = new WP_Query(array('posts_per_page' => $count, 'post_type' => 'posttype', 'orderby' => 'menu_order','order' =>'ASC'));      
    $list = '<div class="post_list_area">';
    while($q->have_posts()) : $q->the_post();
        $idd = get_the_ID();
        $custom_field = get_post_meta($idd, 'custom_field', true);
        $post_content = get_the_content();
        $list .= '
        <div class="single_post_item">
            <h2>' .do_shortcode( get_the_title() ). '</h2>
            '.wpautop( $post_content ).'
    $list .= '</div>';
    return $list;
add_shortcode('post_list', 'post_shortcode');  

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 15 =