Skip Navigation

[Resolved] Custom search to hide posts with a specific tag

This support ticket is created 4 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by donC-3 4 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1818305

The search page is at hidden link (to see the toolset one you have to click the show visual search). but the key is I want to have it so when searching, posts with a specific tag don't come up. Any way to do that?

#1820881

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the view's filter hook wpv_filter_query that will allow you to modify the view's query on fly and you can hook in the unwanted tag using tax_query.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

If you do not know how to use it, you can please share the search key word I should use as well as the tag which you want to exclude and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1825617

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the following view's filter hook to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_query', 'func_exclude_post_tag', 99, 3 );
function func_exclude_post_tag($query, $setting, $views_ID) {

      if($views_ID == 1111) {
            $query['tax_query'][] = array(
            'taxonomy' => 'post_tag', // taxonomy name
            'field' => 'slug',
            'terms' => 'ldccontest', // term slug for exclude
            'operator' => 'NOT IN'
            );
		$query['tax_query']['relation'] = 'AND';
}
return $query;
}

I see with the following post the tag "ldccontest" is assigned:
=> hidden link

And when I try to search with the keyword: autumn
=> hidden link
I do not see any results. Can you please confirm it works as expected.

#1826039

My issue is resolved now. Thank you! Worked perfectly.