Showing wrong page after querying custom post type (3 posts)

  1. John Huebner
    Posted 3 years ago #

    I have created a custom post type. The idea is that the posts from this custom post type will be displayed in the header of the home page, outside of the loop.

    In my home page header file I have something like the following:

    $type = 'home_page_header_posts';
    $args  =  array('post_type' => $type,
                  'post_status' => 'publish',
                  'posts_per_page' => -1,
                  'caller_get_posts'=> 1,
                  'orderby' => 'menu_order',
                  'order' => 'ASC');
    $query = new WP_Query($args);

    Then I have a loop to loop through these posts and display them.

    The problem is that when the main content is displayed, instead of showing the home page content what is shown is the content from the first post in my custom post type.

    I have tried every thing I can find about how to reset the query and show the correct post.

    ie: wp_reset_query, wp_wp_reset_postdata, I have tried reseting it and not reseting it as I saw that idea somewhere in my search. So I have tried all of the available methods that I can find, still nothing. I cannot get the correct page to display.

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    please post the full code of the template, or at least of the custom loop.

    if the code is longer, please use the pastebin - http://codex.wordpress.org/Forum_Welcome#Posting_Code

  3. John Huebner
    Posted 3 years ago #

    it appears I have figured it out. I was not using have_posts() and the_post() to loop through the posts from the custom post type and was accessing the data directly. I altered the loop to use these and now wp_reset_query() works as expected

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.