Title: The Loop -&gt; variable? (NOT $post)
Last modified: August 18, 2016

---

# The Loop -> variable? (NOT $post)

 *  Resolved [babylona](https://wordpress.org/support/users/babylona/)
 * (@babylona)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/)
 * 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)

 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244878)
 * _“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](https://wordpress.org/support/users/babylona/)
 * (@babylona)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244881)
 * 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.
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244884)
 * It’s in the file wp-includes/template-functions-post.php
 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244885)
 * _“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](https://wordpress.org/support/users/babylona/)
 * (@babylona)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244887)
 * 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.

## Tags

 * [get_the_content](https://wordpress.org/support/topic-tag/get_the_content/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [babylona](https://wordpress.org/support/users/babylona/)
 * Last activity: [20 years, 9 months ago](https://wordpress.org/support/topic/the-loop-gt-variable-not-post/#post-244887)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
