Guest User

Untitled

a guest
Sep 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. function limit_search_author( $query ) {
  4.  
  5. if ( $query->is_search ) {
  6.  
  7. $current_user = wp_get_current_user();
  8.  
  9. if ( !( $current_user instanceof WP_User ) )
  10. return $query;
  11.  
  12. if ( 0 != $current_user->ID ) {
  13. $query->set( 'author', $current_user->ID );
  14. }
  15.  
  16. }
  17.  
  18. return $query;
  19.  
  20. }
  21.  
  22. add_filter( 'pre_get_posts', 'limit_search_author' );
  23.  
  24. ?>
Add Comment
Please, Sign In to add comment