WordPress.org

Ready to get started?Download WordPress

Forums

get_the_content() doesn't work in single view? (7 posts)

  1. jwvanderbeck
    Member
    Posted 8 years ago #

    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.

  2. tsguitar
    Member
    Posted 8 years ago #

    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.

  3. jwvanderbeck
    Member
    Posted 8 years ago #

    Yeah I tried that and even $localcontent is empty.

  4. tsguitar
    Member
    Posted 8 years ago #

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

  5. jwvanderbeck
    Member
    Posted 8 years ago #

    Amazing.

    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*

  6. $post->post_content should work as well.

  7. tsguitar
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic