Skip Navigation

[Resolved] Multiple loops duplicate content

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 8 replies, has 2 voices.

Last updated by Joe 6 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#559100

Joe

Hello,

Does views support the creation of multiple loops without content duplication?

I would like to create a page that has multiple views in it. The first view will show 5 posts from all categories. The second view on the page will only show posts from 1 category. Likewise, a third View will only show posts from 1 specific tag.

Is there a way to make it so that Views 2 and 3 aren't showing some of the posts that may be found in View 1? An offset I know cannot work here.

Basically I would like to do what's described in the Codex here:

https://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

Thanks.

#559145

You just need to create 3 Views and insert them into the page.

The first View shows the posts show five posts from all categories (this means you set the Limit and Offset to "limit:5) and use no Query Filter.
The second View shows the posts from one category (this means, you use a Custom Query here, and delimit the output to "any of the following:" ==> check all terms)
The third view is like the second, but you delimit "any of the following:" ==> check single terms

You will need 3 views (or as many Views as different Loops you need)

#559239

Joe

Hello Beda.

I'm not sure if I am missing something here or not setting up right, but following your directions gives me the results I do not want.

View #2 although specific to one category, shows some repeats from what is in view number 1 which shows posts from all categories.

If view number 1 is showing a post from a category that is specific to view number 2, view number 2 needs to skip that post and go onto the next one.

Perhaps the Codex describes it better than me which the use case is:

"Leaving all formatting and CSS issues aside, let us assume we want to have two lists of posts. One which would list the most recent posts (the standard 10 posts most recently added), and another which would contain only one post from the category ‘featured’. Posts in the ‘featured’ category should be shown first, followed by the second listing of posts (the standard). The catch is that no post should appear in both categories.

In other words, I have posts appearing in the "featured" category, that are also found in the all categories listing. If they are already showing in the featured section, I do not need them to repeat in the all section. Can views accomplish this or does it require custom coding?

Thanks.

#560213

View #2 although specific to one category, shows some repeats from what is in view number 1 which shows posts from all categories.

If view number 1 is showing a post from a category that is specific to view number 2, view number 2 needs to skip that post and go onto the next one.

This cannot happen, if you have three different Views, with three different Queries.

As long the Queries are explicit, and not calling for the same kind of Taxonomy, Field or another kind of shared data, it cannot return the same results.

I would like to see what you created so I can eventually help to adjust the Queries.

I would need to request temporary access (WP-Admin and FTP) to your site
- Preferably to a testing ground where the problem has been replicated if possible -
To be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site.
This is also a reason the backup is critical
✙ Please add the Links to:
- Page where the Views are inserted
- Views created
- a few example posts that are showing mixed up but should show only in one specific View

#560797

Please confirm what I see.

1. There are more than three views on that Content Template, but I think you mean these:
- Popular Posts Sidebar
- All categories on homepage
- all categories on homepage small images

Right?

2. Popular Posts Sidebar Includes only posts with individual IDs.
Hence it will return exactly those items.

3. All categories on homepage return one post only, and it will always be the newest.
There is no other query here, so, this post will always be the latest published.

4. all categories on homepage small images display four items, always the newest, just as #3 above, but instead of one, 4.

Is this correct?

So the result will be:
- certain fixed Items (by ID)
- The latest post
- The most recent post + the following latest 3.

There is nothing I see wrong with that, but it does not match what you state, that your query by taxonomy and those mix up in the views.

If this is not correct, please follow this instruction and provide me with the right data to look at:
https://toolset.com/forums/topic/multiple-loops-duplicate-content/#post-560213

Thank you!

#560850

Joe

Hi Beda,

Unfortunately this is not all correct.

Yes, there are more than three views in the loop, but I only described specifically 3 views that need to be looked at, and popular posts was not one of them. I see why there was some confusion though.

Please review my last private response. Although I did not name exactly what each view that needs to be looked at is called , I did say what each view contains, none of which were popular posts.

"1. There are more than three views on that Content Template, but I think you mean these:
- Popular Posts Sidebar
- All categories on homepage
- all categories on homepage small images"

The last 2 things are correct with all categories. I mentioned the third thing to look at by name in the private fields. I have updated the content template to remove some ad code so that should make it easier to view. There are 8 Views used with the template. If you are able to solve the issue in regards to the 3 Views I mentioned, I should be able to handle the other ones that will need to be updated on my own. Popular posts is actually the only view out of all 8 that has nothing to do with what I'd like to be accomplished.

#561127

There are 52 Views on this page, Joe, and none of them queries a "Deals" post type.
I apologise that by your description I am not able to find it.

Please understand me, that if I ask to point me to the proper view, and activate a private reply, it could be easy to pass me the ID, or Link to it, and then I could look at it in one shot and either fix, propose or state something in regard.

I found a View that is called "<erased the name of the view as per client request> you refer to?
This view has no filter, no offset, no limit and no other queries; it will, therefore, return ALL posts of that kind, newest first.

It will not return posts, as the first two views query.

I assume I still did not get the correct Views.

Please can you pass me this information in the next private reply so I can help you accurately:

1. Screenshots of the front end, where you mark in a red rectangle or similar, the areas where you see replicated content
2. The backend URL's of those Views
3. The related Posts (some examples, that are replicated, and in your opinion should appear only once) (the links to them, in the backend)

The reply is marked as private, in case sensitive data is included.

#561475

Yes, I know those Views are in that Content Template, but it does cost 1 minute to paste those links, it cost us four days to get to the right Views by now, due to the missing direct links.

I cannot guess the location of the code, if there are more than 3 Views and not a clear way to get to them, I am sorry.

I want to point out that we cannot support very well if we have to speak about anonymous Data.

If you are concerned about this, I suggest to use Numeric or Random view names and then we can talk about them publicly; it makes the process easier.

Of course, I respect your privacy!
And that is why I will not paste any name of any item anymore in this ticket, but this will make communication a lot more difficult, I hope you understand that.

I can unfortunately not reply privately, that is why I suggest changing the names of those views to a numeric value so we can speak about them openly.

It's not meant as a critique; it's a suggestion so we can proceed faster.
This is mainly to your advantage.

Now, I checked those 3 Views.

1. View One:
- it Queries Posts
- It shows one result
- it is the last published one

2. View Two:
- it Queries Posts
- it shows four results
- it skips the first result
- it shows the last published ones
- this view also has nested views

3. Third View:
- it Queries Posts
- it shows three results
- it shows only posts with the Category "Erased as might be a confidential name."
- it shows the last published ones

So, it is perfectly expected that the Item display in View #1 is also in the View #2.

If you want to remove that item from View #3, you need to offset by one.

Then the only item displayed in View #1 will never be shown in View #2.
(Always the last post published.)

The same is expected for View #2 items, since those three views query the same posts, by no other difference but the taxonomy query and an offset/limit, it is of course expected to have the present in all views.

The only way to avoid this is to categorise more, and then query by specific Terms, or to add some Custom Fields, and query by those, or use another approach of Display altogether.

You can't use the same method as in the PHP example in the codex, where they populate a $do_not_duplicate with a Post ID and skip that ID when creating the second loop.

I am sorry that I did not recognize at first what you were precisely asking.

What you can do with Views to achieve this (this is the closest you can get) is a nested View:

1. Create a "parent View" where you return a limited set of posts (let's say the latest one)
2. Create a "Child View" where you return all OTHER posts, and set a Query Filter like this:

Exclude posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]

This is the primary filter that will EXCLUDE all previously already displayed posts. You can, of course, add more filters.
3. Insert this Child View to the Parent View Loop (here it is important that the first, parent View always returns only ONE result)
4. Pass the post-ID ShortCode the Child View when you insert it to the parent view's loop:
[wpv-view name="test-view" ids="[wpv-post-id]"]
5. Then insert the Parent View to your page.

This will produce a list of:
- ONE post (from parent View)
- a LIST of Posts, from the child View, which will EXCLUDE the post returned in the Parent View.

This will NOT work if the parent view displays more than one post, as then, the child View will be rendered too many times.

#561794

Joe

Hi Beda.

Thank you.

I was able to test your suggestion out and get it to work. However, I don't think the posts can be displayed in a way that I would like them to by using this method. It may be best for me to try and learn some php then.

Thanks again.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.