Reply To: Searching by custom posts not restricted by user

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Searching by custom posts not restricted by user Reply To: Searching by custom posts not restricted by user

#11154
Ernest Marcinko
Ernest Marcinko
Keymaster

Hi Steve,

I’ve looked up the LMS plugin code, and I have found a possible solution. I’ve made a minor modification to the initial custom code, for future reference it is now:

add_filter( 'asp_results', 'asp_filter_posts_by_capability', 1, 1 );
function asp_filter_posts_by_capability( $results ) {
	foreach ($results as $k => &$r ) {
		if ( !sfwd_lms_has_access($r->id) )
			unset($results[$k]);
	}
	return $results;
}

I have found that the “sfwd_lms_has_access” function should always return if the user has access to the particular object (lesson, topic, quiz etc..). So I changed the code according to that.

From my initial tests this appears to be working, but of course let me know if you find anything.

I’ve also increased the results limit to 25 from the initial 10, because in cases where the results pool is greater than the limit and none of the courses are accessible to the user from that pool, he might not get any results at all, because the results are removed after the search, during the post process.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)