• Resolved sefanjo

    (@sefanjo)


    Hi,

    On my site I need 2 loops running, one loop is just for the normal posts and the other are from a custom post type that I have made.

    I know there is something to do with WP_Query.

    Here is a link to the code:
    http://pastebin.com/dNJw248W

    The first loop runs without any problems,
    but the seconds just displays the Error. (Else statement)

    I hope someone has a solution to displays the 2nd loop that has to display the custom post type.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi!

    Hope you are doing good!

    I think part of the reason could be because you are not resetting the post data. If you look at the documentation page: https://codex.wordpress.org/Class_Reference/WP_Query

    Quick excerpt:

    $query1 = new WP_Query( $args );
    
    // The Loop
    while ( $query1->have_posts() ) {
    	$query1->the_post();
    	echo '<li>' . get_the_title() . '</li>';
    }
    
    /* Restore original Post Data
     * NB: Because we are using new WP_Query we aren't stomping on the
     * original $wp_query and it does not need to be reset with
     * wp_reset_query(). We just need to set the post data back up with
     * wp_reset_postdata().
     */
    wp_reset_postdata();
    
    $query2 = new WP_Query( $args2 );
    while ( $query2->have_posts() ) {
    	$query2->the_post();
    	echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
    }
    
    // Restore original Post Data because we always cleanup after ourselves
    wp_reset_postdata();

    Hope that helps!

    is the custom post type using the default categories or custom taxonomies?

    Thread Starter sefanjo

    (@sefanjo)

    The custom post type is using default taxonomies @michael

    Thread Starter sefanjo

    (@sefanjo)

    @jose Castaneda , I’ve allready tried to rest it but that did not help..

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Multiple loops’ is closed to new replies.