• I was trying to figure a way to use preg_match_all() to output the number of times the search string appeared in the post, and I was wondering if there was any way to create a variable whos contents were the_content(). $content = the_content() doesnt work, as it just displays the content in the , and adding quotes only makes it take the literal string of text, the_content(), instead of the actual contents of the post. Any help on this is much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you want the content with all filters applied:

    $content = apply_filters('the_content', get_the_content());

    If you want just the raw content:

    $content = get_the_content();

    Thread Starter breakfastclubber

    (@breakfastclubber)

    Thanks, this works great! If you’re interested, here’s what I’m using it for:

    $content = get_the_content();
    echo preg_match_all("/$s/i", $content , $matches) . " instances of ".$s." found in the text.";

    This would show how many times the search string appeared.
    Anyways, thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘set a variables contents as the_content()’ is closed to new replies.