Knowledge Base - Ajax Search Pro for WordPress...
Knowledge Base - Ajax Search Pro for WordPress...
Buy Ajax Search Pro!
Documentation
Get Support
Knowledge Base
Safe Coding Guideline
Hooks
Filters
Templating
Frontend Filters
Taxonomy Filters
Frontend filters API
Tips & Miscellaneous
Tutorials
Post Types
Limit results to specific post IDs only
Filter posts (or CPT) which user can’t access
Restricting results by user Groups using the Groups plugin by itthinx
Limiting results to specific posts by parent ID
Limit results to current page children
Excluding posts or CPT by parent ID(s)
Searching posts, pages (or any CPT) by specified keywords only, nothing else
Showing the post type name in result title
Searching within given categories/taxonomy terms only
Search only in the same category as the current post or page (single page)
Search only within the current category (or any taxonomy) archive
Taxonomy Terms
WooCommerce
Compatibility
Other
Other
Javascript API
Javascript Hooks
Changelog
Powered by GitBook

Filter posts (or CPT) which user can’t access

The only way of checking and filtering the posts not accessible by the current user is during the post processing of the search results.

​What is this, and where do I put this custom code?​

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

​

Previous
Limit results to specific post IDs only
Next
Restricting results by user Groups using the Groups plugin by itthinx
Last updated 7 months ago