Skip Navigation

[Resolved] Post appear in a View multiple times if in multiple categories

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View of posts filtered by taxonomy, and I want each post to appear multiple times depending on the number of terms that match the filters.

Solution:
The only way to show a post multiple times in a single View is to use the wpv_filter_query_post_process filter to manipulate the View's results after the filters are applied.

Or, use a View of posts nested inside a View of terms, and set up the filters as links that update the URL parameters correctly.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

This support ticket is created 6 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#902466

I have a page here:

hidden link

Click on 'Clinical' and then all of the sub-categories to make all posts appear. There are 6 but I want each post to appear multiple times if it is in multiple sub-categories.

I think this is independant of the isotope filter so doesnt need to factor that in, just that in the view I have created, a post will feature once for each category it is in.

Regards,

David

#902560

Hi, the only way to make a post appear multiple times in a single View's results is to apply some custom code that modifies the result set using wpv_filter_query_post_process:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
In theory you could loop over the existing results and make clones as needed based on has_terms or something similar, then modify the pagination and post count values to match the final result set. When you factor in pagination, you can see how this becomes quite complex.

One alternative I can think of is to use two nested Views - one for the Supplier Categories and another for the Suppliers.
- View 1: A View of the Supplier Category taxonomy that is filtered by term, set by a URL parameter
- View 2: A View of Suppliers filtered by Supplier Category where the term is set by the parent taxonomy loop
- Insert View 2 inside the Loop of View 1.

Then you will have to recreate the filter buttons to work with View 1, so that the buttons work as links and update the URL appropriately, triggering an update of View 1. It will work best without AJAX updates, but you could probably make some JavaScript adjustments to work with AJAX.

You will also have to consider that the nested Loop structure will create nested markup, so you may have to do some DOM manipulation to get things to work in the Isotope system.