WordPress.org

Ready to get started?Download WordPress

Forums

Get excerpt as variable? (7 posts)

  1. jeremyduffy
    Member
    Posted 5 years ago #

    Is there a simple way to do that or will I have to look it up manually?

  2. Roy
    Member
    Posted 5 years ago #

    What is your question?

  3. Doodlebee
    Member
    Posted 5 years ago #

    Do you want a specific excerpt, the most recent one, or a random one...need a little more clarification please.

  4. jeremyduffy
    Member
    Posted 5 years ago #

    Given a specific post id, what's the best way to get it's excerpt into a variable? Querypost?

  5. Doodlebee
    Member
    Posted 5 years ago #

    $excerpt = get_the_excerpt();

    It has to be within the loop. If you want a specific post excerpt outside the loop:

    global $post;
    get_post('7');
    $excerpt = $postid->post_excerpt;

    That'll return the excerpt for the post with an ID of "7".

  6. jeremyduffy
    Member
    Posted 5 years ago #

    Awesome and great detail doodlebee. Thanks!

  7. amuralikumar
    Member
    Posted 4 years ago #

    Use get_the_excerpt() function.

    EXAMPLE :<?php
    $myExcerpt = get_the_excerpt();
    if ($myExcerpt != '') {
    // Some string manipulation performed
    }
    echo $myExcerpt; // Outputs the processed value to the page
    ?>

    for more check http://codex.wordpress.org/Function_Reference/get_the_excerpt

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags