PHP – How do I get `<?php the_content(); ?>` as a string or turn it into a string

I use a lot the function:

get_search_query() 

To get the value returned from searches and to be able to modify and use the string.

Read More

I need to know a function to get <?php the_content(); ?> as a string or how to turn what that function returns into a string.

The content is just a simple word with paragraph tags but using that function I also get the tags, I want to get just the text so I can add it to a hyperlink.

Related posts

Leave a Reply

5 comments

  1. Don’t know WP, but the implied naming convention would suggest get_the_content(). Additional googling reveals a variation get_the_content_with_formatting

    An alternative would be however to wrap the_content() into ob_start() and ob_get_contents()+ob_end(). The latter returns any print output made until then.

  2. $the_post = get_post();
    $the_post->post_content;
    

    Full list of things you can get using this method:

    [ID] =>
        [post_author] =>
        [post_date] => 
        [post_date_gmt] => 
        [post_content] => 
        [post_title] => 
        [post_excerpt] => 
        [post_status] =>
        [comment_status] =>
        [ping_status] => 
        [post_password] => 
        [post_name] =>
        [to_ping] => 
        [pinged] => 
        [post_modified] => 
        [post_modified_gmt] =>
        [post_content_filtered] => 
        [post_parent] => 
        [guid] => 
        [menu_order] =>
        [post_type] =>
        [post_mime_type] => 
        [comment_count] =>
        [filter] =>