logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
'dual' loop to include featured cat in first post

What I am trying to do:

I have a 'dual' loop setup so that I can display the 4 most recent posts from my custom post-type 'photogallery' on the top, and then continue to loop through the rest of the posts.

example:

<?php $my_query = new WP_Query('post_type=photogallery&posts_per_page=4'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate[] = $post->ID;?>

<!-- do stuff -->

<?php endwhile; ?>

<?php if (have_posts()) : $count = 0; ?><? while (have_posts()) : the_post();
if (in_array($post->ID, $do_not_duplicate)) continue; $count++; ?>

<!-- do more stuff -->

<?php endwhile; else: ?>
<?php endif; ?>


What I need:

On the top loop I want to show the 4 most recent posts from the post_type photogallery with the term 'featured' from the custom taxonomy 'gallerycategories'.

I don't want those posts duplicated in the lower loop, and I want my lower loop to continue through the posts just like it does now.

**This is used on my photogallery archive.php page, so I need to show all the photogallery posts in the lower loop, not just one's with the term 'featured', yet still make sure to exclude the featured posts that are on the top loop from the bottom loop.

What I am missing:

I don't know how to add in the part about the term 'featured' into the top portion of the loop. When I try to insert my logic for the term, it ends up also passing to the lower loop, thus only showing posts from the featured term. Everything else works perfectly.

thank you

This question has been answered.

shawn | 12/04/10 at 2:09am Edit


(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    12/04/10
    2:59am
    Nilesh shiragave says:

    Hi

    Try this



    <?php $my_query = new WP_Query('post_type=photogallery&posts_per_page=4'); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    ?>



    <!-- do stuff -->



    <?php endwhile; ?>



    <?php if (have_posts()) : $count = 0; ?><? while (have_posts()) : the_post();

    if( $post->ID == $do_not_duplicate ) continue; $count++; ?>



    <!-- do more stuff -->



    <?php endwhile; else: ?>

    <?php endif; ?>

    • 12/04/10 2:23am

      shawn says:

      That is exactly what I have already. I need the logic added to the loop to only show 4 posts from the post_type photogallery with the term 'featured' from the custom taxonomy 'gallerycategories', and then show the rest of the posts below.

      I don't see any of that logic in there.

    • 12/04/10 2:32am

      Nilesh shiragave says:

      so posts are displaying without duplicating in the second loop right? Only issue is with the first loop to display post_type photogallery with term 'featured' ?

    • 12/04/10 2:33am

      shawn says:

      yes, the loop is working perfectly without duplicating posts. Just need first loop to only show term featured, and make sure those 4 are not duplicated in 2nd loop

    • 12/04/10 2:52am

      Nilesh shiragave says:

      Try this instead of the first query


      <?php $my_query = new WP_Query(array('post_type' => 'bookphotogallerys', 'gallerycategories' => 'featured','posts_per_page'=>4)); ?>

    • 12/04/10 2:53am

      Nilesh shiragave says:

      Try this instead of the first query


      <?php $my_query = new WP_Query(array('post_type' => 'photogallery', 'gallerycategories' => 'featured','posts_per_page'=>4)); ?>

    • 12/04/10 2:57am

      Nilesh shiragave says:

      Try this instead of the first query


      <?php $my_query = new WP_Query(array('post_type' => 'photogallery', 'gallerycategories' => 'featured','posts_per_page'=>4)); ?>

    • 12/04/10 2:58am

      shawn says:

      Thank you, works perfectly, now I see where I was going wrong earlier, dumb mistake...

      Just in case your interested, I have a similar unanswered question:
      http://wpquestions.com/question/show/id/1258

      Picking you as winner on this one as it works.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.