Skip Navigation

[Resolved] Split: Re-using custom code

This support ticket is created 5 years, 3 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
- 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+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by francescoG-3 5 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#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

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01: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!

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