• Resolved babylona

    (@babylona)


    Hi all. I’ve been hunting and so far come up mostly empty. What I would like to do is send the entirety of the output of The Loop into a variable so I can handle display myself.

    I found and started using the $post variable, but while the Wiki claims that all Loop information is accessible from $post, that is untrue. I can make the extra call for get_post_meta, which is not ideal but is certainly doable. Where I’m getting hung up is with the_content. I would much prefer to use the_content() to fetch home page excerpts, since it is already there, but the_content has NO parameter to take display=FALSE. Furthermore (I think because of the way the functions are structured) output buffering via php fails to prevent the output itself (I get the output in the buffer, but it outputs to the page as well.)

    Does anyone know of a way to get the result of the_content into a variable? Or another way to do this?

    $post would work fine, except for the missing excerpt functionality (perhaps because I am using post_teaser? if so, dang, because I prefer post_teaser.) The reverse would also be fine – assigning the function results inside the Loop to individual variables – but only some of the functions use the display parameter, somewhat inexplicably (not sure why only some of the functions allow display=FALSE; I would have expected either all content-producing functions to do so or none.)

    Any help is much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • “Does anyone know of a way to get the result of the_content into a variable? Or another way to do this?”
    Try the following:
    $your_variable = get_the_content();

    Thread Starter babylona

    (@babylona)

    Thanks much for that. Do you happen to have a link to the documentation for that function (or know where I could find it)? Searches for get_the_content on both the Wiki and the Codex turn up nothing.

    It’s in the file wp-includes/template-functions-post.php

    “Do you happen to have a link to the documentation for that function”
    Sorry, Unfortunately I don’t.
    I found this by examining the source code for an earlier project that I had.

    Thread Starter babylona

    (@babylona)

    thanks to both of you. For future searchers, since the template function codex documentation has a ways to go yet ?? –

    function get_the_content($more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”)

    … where the function call must be made within the Loop for multiple posts including the excerpt. Outside the loop the function appears to return the entire content of the given post, as would be expected. The parameters appear to be identical to those for the_content, and, in fact, the_content calls get_the_content.

    I’ll add some tags to this post as well.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘The Loop -> variable? (NOT $post)’ is closed to new replies.