WordPress.org

Ready to get started?Download WordPress

Ideas

Get content/excerpt by id

  1. Ashworth Creative
    Member

    It's already pretty easy to get titles and permalinks by id, can there also be a simple function to get the content/excerpt of a post by id? This would make working with excerpts much easier, and make it easier to work with content outside the loop.

    Posted: 1 year ago #
  2. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    Semi easy.

    If you use get_page() you can pull it:

    $page_data = get_page( $post_id );
    
        $excerpt = strip_tags($page_data->post_excerpt);
    
        echo $excerpt;
    Posted: 1 year ago #
  3. That doesn't apply the appropriate content filter to the excerpt, and it only works if there is a manual excerpt.

    Posted: 1 year ago #
  4. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    You can use the same logic to pull in the first X characters of the content for an auto-excerpt, or better, make your own function to do both and call that instead.

    And what 'content filter' are you missing?

    Posted: 1 year ago #
  5. I'm referring to the the_excerpt and the_content filters. I was really hoping for native methods similar to get_the_title(), that pulls in the requested data and applies the relevant filter, based on a post id.

    Posted: 1 year ago #
  6. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    Those functions were written around get_post() :)

    http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/post-template.php#L260

    So my point was that you can do this, same way core did. Write your own function for it. The the_excerpt() stuff was explicitly written to work in the loop, which is why you'd have to make a second one for yourself. Adding in ways to make it work outside of the loop really would be the realm of a second filter, since it's part of the post template functions, which get content for the current post in the loop.

    It'd be a cool plugin to add in those functions, and if it got picked up a lot, it may end up in core :)

    Posted: 1 year ago #
  7. Tekmoz
    Member

    I know this is an old topic now but I'm still having to use the preview button to get the id from the url, has there been any progress on this? If there has I must have missed it, is there an easier way to get the id yet?

    Posted: 3 weeks ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    5 Votes
  • Status

    This idea is under consideration