Problem: I have a View that shows a list of posts in a custom post type. Some of my posts have the same title. I would like to remove the duplicate titles from the View. How can I filter by unique post title?
Solution: There is no simple way to filter duplicate titles from wp-admin. You could implement your own custom code that uses the wpv_filter_query API or the wpv_filter_query_post_process API to filter out matching titles, or you can use this jQuery snippet to hide them on the frontend:
jQuery(document).ready(function(){ var strs = []; var dupes = []; jQuery('.wpv-loop').find('li > a').each(function(index,item){ var txt = jQuery(item).text(); if( strs.indexOf(txt) > -1 ) { dupes.push(index); } else{ strs.push(txt); } }); dupes.reverse(); for(var i=0; i<dupes.length; i++) { jQuery('.wpv-loop').find('li').eq(dupes[i]).remove(); } });
Note that the duplicates may appear momentarily on the front-end until the JavaScript has been executed.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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)
Dieses Thema enthält 4 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 6 Jahren, 9 Monaten.
Assistiert von: Christian Cox.