WordPress.org

Support

Support » How-To and Troubleshooting » Duplicate post issue on multiple category loops on one page

Duplicate post issue on multiple category loops on one page

  • I am building a homepage template and it has an area with 4 separate category loops in a grid layout. Each loop will only show one post. The posts that I will be working with have multiple categories assigned to them and we don’t want to have more than one instance of a post displaying amongst the 4 loops. For example if my latest post is assigned to all of the 4 categories that are setup to loop on the homepage, how can we set a priority so that it only displays in one of the categories and not the other three? I tried excluding the 3 other categories inside of each of the loops but then it just skips over all posts until it finds one that only has one category assigned to it and that won’t work for this project. Let me know if you need further clarification.

    Does anyone have any thoughts or ideas on this.

    Thanks,

    Andrew

Viewing 1 replies (of 1 total)
  • I believe this will work:

    Inside each of the first 3 while() loops, add the ID to an array:

    while (have_posts()) : the_post();
       $do_not_duplicate[] = $post->ID;
       // rest of loop
    endwhile;

    In the last 3 queries, add the 'post__not_in' => $do_not_duplicate, argument to the query.

Viewing 1 replies (of 1 total)
  • The topic ‘Duplicate post issue on multiple category loops on one page’ is closed to new replies.
Skip to toolbar