Skip Navigation

[Resolved] developer hooks

This support ticket is created 2 years, 10 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
- 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 11 replies, has 2 voices.

Last updated by columD 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2080863

I am working with hidden link to make their filters compatible with the Toolset view.

They wanted me to ask you:
We need to modify the argument of get_posts() function used in the blocks of Toolset View block because we need to pass argument 'supress_filters' => false .

Do you have any developer hook we can use for that?

#2081085

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

Toolset views use WordPress Query class ( ref:https://developer.wordpress.org/reference/classes/wp_query/ ) and to filter this query for the posts view, you can use the "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

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

regards,
Waqar

#2081887

Hi Waqar,

Their developer tried to add a post_where filter but is not affecting that section.

Their plugin basically we use the wordpress post_where filter to remove posts that shouldn't show.
post_where filter it's executed in WpQuery, but that section in our home page is not filtering for some reason.

Can I provide you access to where you can take a look?

#2083059

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

If your goal is to exclude specific posts from the view's query, you can use the 'post__not_in' parameter with the 'wpv_filter_query' filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters

For example, suppose you have a view with ID "12345" and you'd like to exclude the posts with IDs "67" and "89" from the view's output. The filtering function would look like this:


add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
	
	// process if specific view
	if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {	
		$query_args['post__not_in'] = array(67, 89);
	}
	return $query_args;
}

Using this example, you or your developer can make the list of posts to exclude dynamically, using the criteria that you have in mind.

#2083303

Hi Waqur,

We couldn't get it to work.

They commented out their fuction that return the posts that needs to be excluded and I simply hardcoded the post id number like this: $query_args['post__not_in'] = ['1864'];

add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {

    // process if specific view
    if ( !is_admin() ) {   
//        $query_args['post__not_in'] = get_geotargeted_posts();
		 $query_args['post__not_in'] = ['1864'];
    }
    return $query_args;
}

and it's still didn't remove the post from the view. Can I provide you access so you can take a look?

#2088421

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and it is strange that the code didn't work for you.

I've set your next reply as private so that you can share temporary admin login details, along with the link to the page where this view can be seen.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

#2090049

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the admin access.

It is strange that the post exclusion through "wpv_filter_query" is not working on this website.

Do I have your permission to download a clone/snapshot of the website?
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

This will help us in investigating this in more detail on a different server.

#2090549

Hi Waqar,

Yes of course, please proceed.

#2091525

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for the permission and I've downloaded the website's clone.

I'll need to perform some tests and will update you with my findings as soon as it completes.

Thank you for your patience.

#2091527

Hi Waqar,

Thank you for the follow-up! Looking forward to your findings.

#2095571

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting, as I investigated this rather odd behaviour.

During troubleshooting, I noticed that some custom script is added in the view "All Resources For Home Page".
( screenshot: hidden link )

The custom function is working as expected to exclude the post with ID "1864", but after the page loading has completed, this custom script automatically triggers the search with a value in the hidden language field.

If you'll remove this custom script, you'll see that this post with ID "1864" will not be shown by the view.

#2095695

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.