Support » Plugins » get_the_content() doesn’t work in single view?

  • It seems that if I call get_the_content when i’m in a single view, it doesn’t return anything.

    Is this true or is my code bad?

    if ((in_category(4)) or (in_category(6)))
    if (($is_home) or ($is_single))
    $localcontent = get_the_content("", true, "");
    $loc = strpos($localcontent, "<!--split!-->");
    $start = $loc + 13;
    $end = strlen($localcontent) - $start;
    $finalcontent = substr($localcontent, $start, $end);
    echo $finalcontent;

    Couple notes on the above code:
    The use of local variables such as $is_single is because for some odd reason at this point in my code, calling the template boolean is_single() doesnt’t work right, so I cache them up before I start the_loop.
    This code exists inside the_loop.

    The code works perfect when i’m in a home view, but when i’m in a single post view, nothing is returned from get_the_content.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Have you tried to only display the $localcontent variable without all that parsing? I’m just thinking that maybe the pasing you’re doing is causing the problem. Just echo $localcontent instead of $finalcontent and tell me what happens.

    Yeah I tried that and even $localcontent is empty.

    And if you change the variable to this:
    $localcontent = get_the_content("", false, "");
    what happens?


    Well I have no idea WHY that works, since all that param is supposed to do is supress the addition of the “more” link, but it does. Thank you very much. I never would have thought ot try that *boggle*

    $post->post_content should work as well.

    Glad to help. Making the change to “false” has to do with displaying the teaser and that has an impact on what content is displayed on the single post pages. Maybe you’re doing something with the “more” quicktag? Keep your eyes peeled here; someone else (moshu?) will come along and explain exactly why this works.

    For now, let’s mark this post resolved.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_the_content() doesn’t work in single view?’ is closed to new replies.