Forums

get_the_content() within second loop doesn't work correctly (2 posts)

  1. wardrox
    Member
    Posted 2 years ago #

    I have a main loop and a plug-in which creates a second loop showing posts from a set category. Normally this works without error.

    However, when the content within the first loop is paged, and the user is looking at anything other than the very first page, get_the_content() returns the content from the first loop that has finished (specifically the data in the page being displayed), not the second loop which it is in.

    Confusing things further, within the second loop the functions the_title() and get_permalink() return data for the correct post.

    Edit: An example of this error is here. On the first page (and any other page on the site) the images (taken from a get_the_content() call) match the titles and articles. However on the second and beyond pages the images match that of the main loop's.

  2. wardrox
    Member
    Posted 2 years ago #

    Fix:

    Not sure which part of this fixes the problem but it seems to be working now. I changed the following;

    Added the line:
    global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;

    Replaces get_the_content() with $post->post_content;

    And moved where I call $my_query->the_post();

    The original bug, whilst now circumvented, still exists.

Topic Closed

This topic has been closed to new replies.

About this Topic