Skip Navigation

[Resolved] Exclude specific category while include some via shortcode parameter

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Shreyas Khatri 5 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1321865

Tell us what you are trying to do?
hidden link

I have same view (view id: 56943) used multiple times on the same page. Each time i'm passing the category from which I want to show post. Example: wpvcategory="wheels". In the views setting, I'm using: "Categories slug in one of those set by the View shortcode attribute wpvcategory"

I've some posts that belong to two categories: 'Current Edition' as well as 'wheels'.

But i want to exclude those article which are in 'current edition'.

I could find similar answer here:
https://wordpress.stackexchange.com/questions/273523/include-posts-from-some-categories-while-excluding-from-others

But how do i do within views? Your help will be highly appreciated.

#1322139

Hi there,

Thank you for contacting us and I'd be happy to assist.

To include an additional fixed taxonomy filter to exclude a specific term's posts, you can use "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Example:


function filter_to_exclude_tax($view_args, $view_settings, $view_id) {

	if (in_array($view_id, array(1234))) {

		$view_args['tax_query'][] = array(
									'taxonomy' => 'taxonomy-slug',
									'field'    => 'id',
									'terms'    => '56',
									'operator'    => 'NOT IN',
									);
	}

	return $view_args;
}
add_filter('wpv_filter_query', 'filter_to_exclude_tax', 101, 3);

The above function can be included in the active theme's "functions.php" file and please replace:
- "1234" with the actual ID of your view
- "taxonomy-slug" with the actual slug of your target taxonomy ( e.g. "category" )
- "56" with the actual term's ID, that you'd like to exclude

I hope this helps and let me know if you need any further assistance around this.

regards,
Waqar

#1322707

Thanks a lot, Waqar, for your kind help! Worked like charm. The said category is now excluded and it's exactly working the way i want it.