Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to search only in posts where the author is the user? › Reply To: How to search only in posts where the author is the user?
October 14, 2014 at 6:32 pm
#2667
Hi again!
If I understand correctly, then you only want to show results, that were created by the current logged in users?
This is only possible by modifying the search source or creating a filtering function. Try to add this code anywhere to your theme functions.php file:
add_filter( 'asp_pagepost_results', 'asp_filter_the_post_author', 1, 1 ); function asp_filter_the_post_author( $pageposts ) { foreach ($pageposts as $k=>$v) { global $current_user; get_currentuserinfo(); $user = get_user_by( 'id', $current_user->ID ); // Get the user nicename $author = $user->data->user_nicename; // Remove the post from the array if the author is not the logged in user if ($pageposts[$k]->author != $author) unset($pageposts[$k]); } return $pageposts; }
- This reply was modified 9 years, 11 months ago by Ernest Marcinko.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)