Sauter la navigation

[Résolu] Split: Re-using custom code

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

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

Dernière mise à jour par francescoG-3 Il y a 5 années et 11 mois.

Assisté par: Nigel.

Auteur
Publications
#1194198

3 - About the custom code in the your first reply in this ticket (https://toolset.com/forums/topic/how-to-create-a-list-to-display-the-last-5-cpt-posts-created/#post-1189646), if I want to use the same code with other View, it need to create a new custom code, cloning the code, change the function name, change the View id, or it is possible to add other View id in this custom code?

#1194464

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Let me reproduce the code here, expanded so that it is used with multiple Views:

function tssupp_filter_query($view_args, $view_settings, $view_id) {
 
    if (in_array($view_id, array(182, 201, 301, 401))) { // Edit View ID(s)
 
        $view_args['author'] = null;
        $view_args['author__in'] = null;
        $view_args['author__not_in'] = get_current_user_id();
 
    }
 
    return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);

By using in_array for the test it is simple to add as many View IDs as you want to apply this to.

#1194748

It work very well, thanks!!!!

#1194749

My issue is resolved now. Thank you!