Skip Navigation

[Résolu] limit View output to one post per author

This support ticket is created Il y a 6 années et 9 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par nicholasM Il y a 6 années et 8 mois.

Assisté par: Christian Cox.

Auteur
Publications
#623027

I have a views parametric search and when the results are displayed it should only be possible for each author to have one result show up for a give criteria as all fields of the search have been made required. So the only way there would be multiple for one author is if they entered the same categories more than once. Unfortunately this would be a way for people to make their results fill up the first page of results so I need to limit the output to one per author. hoping there is a way with conditional output to perform this filter?

#623065

Hi, unfortunately our conditional HTML feature isn't designed to help you hide results this way. If you want to limit the post results to only one per author, then it will require custom code. That falls outside the scope of support we provide here in the forums. A skilled developer might be able to offer a solution using our wpv_filter_query or wpv_filter_query_post_process APIs. We have documentation about those filters here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

We also have a portal available where you may connect with developers with Toolset knowledge here:
https://toolset.com/contractors/

#625036

Thanks, turned out because I always needed only one result in any query on the site I was able to just use a global groupby function however I will probably use the hook you provided to only attach it to that query for best practice.

function filter_authors($groupby) {
  global $wpdb;
  $groupby = " {$wpdb->posts}.post_author";
 return $groupby;
}
add_filter('posts_groupby','filter_authors');