Skip Navigation

[Resolved] I have used 'wpv-conditional' statement as wrapper of loop not working properly

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 6 replies, has 2 voices.

Last updated by Minesh 1 year, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2674387

Tell us what you are trying to do?
I am trying to exclude posts belong to given taxonomies. These Taxonomies are dynamic based on logged in user. This is a single page archive website. I have used [wpv-conditional if="[check-string looking="[wpv-post-taxonomy type="priceline" format="name" hierarchy="primary"]"] eq 0" debug="false"] as a wrapper outside loop and it is working as expected, 'check-string' is custom shortcode which servers comma separated Taxonomy based on logged in user. But the issue is the count of Facet is not correct. Then I tried 'wpv_filter_query' but it is not working for me at all.
Is there any documentation that you are following?
https://toolset.com/forums/topic/need-help-filtering-a-view-using-wpv_filter_query/
Is there a similar example that we can see?
If you search SKU - 02245887 it belongs to Taxonomy 'priceline' and is excluded by wpv-conditional statement but on left facet filters it show (1) instead of (0).
What is the link to your site?
hidden link
This requires Login, let me where I can paste login details.

#2675175

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

if you are on the archive page - you should actually use the WordPress pre_get_posts hook:

You can add the required filters to filter your archive query by adding the pre_get_post hook.

More info:
- hidden link
- hidden link

you can add the pre_get_posts hook to "Custom Code" section offered by Toolset or to your theme's functions.php file:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/

#2675207

Hi Minesh,

Thank you for reply. I have already tried 'pre_get_posts' but it is not working for me.

function custom_filter_posts( $query ) {
if ( ! is_admin() && $query->is_main_query()) {

// Filter by taxonomy terms
$tax_query = array(
'relation' => 'AND',
array(
'taxonomy' => 'priceline',
'field' => 'slug',
'terms' => array( 'keelenon', 'mojbq2','deltan' ),
'operator' => 'NOT IN',
),
);
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts', 'custom_filter_posts' );

Thanks

#2675209

Minesh
Supporter

Languages: English (English )

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

Can you please share problem URL and tell me from what archive you want to remove the post belongs to those terms you mentioned in your previous post?

*** 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.

#2675361

Minesh
Supporter

Languages: English (English )

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

Actually - as you claim that the products are served by WP Solr - you should get in touch with WP Solr plugin support and check with them how you can hook in the taxonomy query which you want on fly before it returns the results.

I see in your functions.php file there are number of times pre_get_posts hooks but most of them are commented. I strongly suggest that you should get in touch with WP Solr plugin support and check with them how you can hook in the taxonomy query arguments and you are most welcome to share the solution here so it may help other users in future.

#2675363

Hi Minesh,

There must some hook at your end where Toolset is plotting the data after getting from WP Solr.

Actually, I have achieved this by conditional statement [wpv-conditional if="[check-string looking="[wpv-post-taxonomy type="priceline" format="name" hierarchy="primary"]"] eq 0" debug="false"] but only issue here is that the filters on the left are not showing count correctly.

Is there any hook / trigger to reset count on demand based on number of products showing currently on the screen.

Regards

#2675369

Minesh
Supporter

Languages: English (English )

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

There must some hook at your end where Toolset is plotting the data after getting from WP Solr.
===>
No - if you go on the following page:
- hidden link

There is a setting "Replace Toolset Archives and Views queries with WPSOLR queries. Think of re-indexing all your data if Toolset Views plugin was installed after WPSOLR." so we can not do much here.

If you were using normal archive - the only way to override the archive query is by using standard WordPrerss "pre_get_posts" hook.

Actually, I have achieved this by conditional statement [wpv-conditional if="[check-string looking="[wpv-post-taxonomy type="priceline" format="name" hierarchy="primary"]"] eq 0" debug="false"] but only issue here is that the filters on the left are not showing count correctly.
===>
Actually - you will have to apply the query filter so that unwanted results should be removed from the query result and you should have actual count. Even if we found a way to get the count but it will not work with pagination as pagination total count will be different. That is why you will have to follow the standard and check with WPSOLR plugin support about how you can hook in the taxonomy query to get your desired result.

#2676383

I have used WPSolr hook 'WPSOLR_ACTION_SOLARIUM_QUERY' and it solved my issue.