Advertisement
dimkiriaoks

Untitled

Sep 22nd, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. function university_adjust_queries($query)
  2. {
  3.     if (!is_admin() and is_post_type_archive('event') and $query->is_main_query()) {
  4.        
  5.         $today = date('Ymd');
  6.  
  7.         $query->set('posts_per_page', '3'); // manipulating the posts
  8.         $query->set('meta_key', 'event_date');
  9.         $query->set('orderby', 'meta_value_num');
  10.         $query->set('order', 'ASC');
  11.         $query->set('meta_query', [
  12.             [
  13.                 'key' => 'event_date', // the custom field name
  14.                 'compare' => '>=', // the operator for the condition
  15.                 'value' => $today, // the value the we are using to compare the key
  16.                 'type' => 'numeric', // the type of key
  17.             ],
  18.  
  19.         ]);
  20.        
  21.     }
  22.  
  23.  
  24.     /**
  25.      * query for program posts
  26.      */
  27.     if (!is_admin() && is_post_type_archive('program') && $query->is_main_query()) {
  28.         $today = date('Ymd');
  29.         $query->set('posts_per_page', -1); // manipulating the posts
  30.         $query->set('orderby', 'title');
  31.         $query->set('order', 'ASC');
  32.     }
  33.     // query for program posts
  34.     if (!is_admin() && is_post_type_archive('campus') && $query->is_main_query()) {
  35.         $query->set('posts_per_page', -1); // manipulating the posts
  36.     }
  37.     // query for program posts
  38.     if (!is_admin() && is_post_type_archive('professor') && $query->is_main_query()) {
  39.         $query->set('posts_per_page', -1); // manipulating the posts
  40.     }
  41. }
  42.  
  43. add_action('pre_get_posts', 'university_adjust_queries');
  44.  
  45.  
  46. /**
  47.  * Redirect Subscriber accounts out of admin and o  n to homepage
  48.  */
  49.  
  50. add_action('admin_init', 'redirectSubsToFrontend');
  51. function redirectSubsToFrontend(){
  52.    
  53.     $ourCurrentUser = wp_get_current_user();
  54.    
  55.     if(count($ourCurrentUser->roles) == 1 AND ($ourCurrentUser->roles[0] == 'subscriber')){
  56.         wp_redirect(site_url('/'));
  57.         exit;
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement