Create a shortcode to display the “the_content ()” in my post [closed]

Here is an example of a shortcode that renders post content based on the id and type attribute.

[post type="content" id="2"]

[post type="title" id="2"]

If you want to render from a template you would use:

echo do_shortcode ( '[post type="content" id="294"]' );

echo do_shortcode ( '[post type="title" id="294"]' );

And here is the actual shortcode registration:

// [post type="content" id="2"]
// [post type="title" id="2"]

function post__shortcode( $atts ) {
    $a = shortcode_atts(
        array (
            'id'   => false,
            'type' => "content",
        ), $atts );

    $id   = $a [ 'id' ];
    $type = $a [ 'type' ];

    // bad id
    if ( ! is_numeric( $id ) ) {
        return '';
    }

    // find the post
    $post = get_post( $id );

    // bad post
    if ( ! $post ) {
        return '';
    }

    // allow for other post attributes
    switch ( $type ) {

        case "content":
            return $id === get_the_ID() || $id === get_queried_object_id()
                ? '' // no recursive loops!
                : apply_filters( 'the_content', $post->post_content );

        case "title":
            return $post->post_title;
    }

    // nothing to see here
    return '';
}

add_shortcode( 'post', 'post__shortcode' );

Obviously you could modify the switch to include any type of content you need for that post.