• I am using list_terms_exclusions filter to remove available categories that users are able to post in.

    However, the code is not always executed when viewing the new post or edit post page.. Seems random as to when it is executing… I don’t see any errors being thrown in the error log.

    /** RESTRICT CATEGORIES **/
    add_filter('list_terms_exclusions', 'myterm_exclude',10,2);
    function myterm_exclude( $exclusions, $args ) {
      global $pagenow;
      if(!current_user_can('manage_options'))
      {
    	if (in_array($pagenow,array('post.php','post-new.php')) ) {
    		$current_user = wp_get_current_user();
    		$userCities = explode(",",get_user_meta($current_user->ID, "user_cities", true));
    		foreach($userCities as &$city) $city = "'" . sanitize_title($city) . "'";
    
    		$userCategories = explode(",",get_user_meta($current_user->ID, "user_categories", true));
    		foreach($userCategories as &$category) $category = "'" . sanitize_title($category) . "'";
    
    		$exclusionsStr = implode(",",$userCities);
    		if(strlen($exclusionsStr) > 0 && count($userCategories) > 0 ) $exclusionsStr .= ",";
    
    		$exclusionsStr .= implode(",",$userCategories);
       		$exclusions = " {$exclusions} AND t.slug IN ($exclusionsStr)";
      	}
      }
    
      return $exclusions;
    }
  • The topic ‘Filter not always called ( list_terms_exclusions )’ is closed to new replies.