get_the_content(“more…”) returns full text

I’m creating shortcode [latest_post] and want to show post date, title and short content. (content has “more” separator). Here is code:

function shortcode_latest_post() {
    global $post, $more;
    $tmp_post = $post;
    $tmp_more = $more;

    $posts = get_posts(array('numberposts' => 1, 'post_status' => 'publish'));

    $output = "";
    foreach($posts as $post) {
        setup_postdata($post);
        $more = 0;
        $output .= '<div class="latest_post">';
        $output .= '<span class="date">'. get_the_date() . '</span>';
        $output .= '<h3><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3>';
        $output .= get_the_content("Read more...");
        $output .= "</div>";
    }
    $post = $tmp_post;
    $more = $tmp_more;
    return $output;
}
add_shortcode("latest_post", "shortcode_latest_post");

But I have problem with “get_the_content” function. It returns full content text instead of short text and more link.

Read More

Can anybody help me, please?

Update:

I’m found solution. Code above is updated. – http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages

Related posts

Leave a Reply

1 comment

  1. get_the_content() does what it’s supposed to, gets the content. You’re looking for get_the_excerpt(). 😉

    Alternatively, using what you have, it should cut off wherever you put <!-- more --> in your post when using get_the_content().