Support

Account

Home Forums Backend Issues (wp-admin) Groups not showing for non-admin users Reply To: Groups not showing for non-admin users

  • The first thing is that query changes like this should only be set on the main query. This is done in the second part, but not on the first.

    
    function altered_search($query) {
    	if($query->is_admin) {
    		// hotfix - wordpress consider all ajax calls as is_admin call
    		// on fronend logged users could see only their items/events
    		// TODO: replace by filter where I can register all custom ajax actions/handlers
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:getHeaderMapMarkers') {
    			return $query;
    		}
    
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:retrieve') {
    			return $query;
    		}
    		
    		// ADD THIS AND TEST
    		if (!$query->is_main_query()) {
    			return;
    		}
    
    		/* Display posts in admin for current user only */
    		$wp_user = wp_get_current_user();
    		if(isCityguideUser($wp_user->roles)){
    			$query->set('author', $wp_user->data->ID);
    		}
    		
    	} else {
    		if($query->is_main_query()){
    			if (isset($_GET['s']) && empty($_GET['s'])){
    				$query->is_search = true;
    			
    			}
    
    			// is woocommerce search
    			if(isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'product'){
    			
    				return $query;
    			}
    			
    		
    			$query = apply_filters( 'ait_alter_search_query', $query );
    			
    			
    		}
    	}
    	return $query;
    }