• So I’m trying to figure out how to clump any terms that begin with a number into a custom tag like “Misc” so that I don’t wind up with 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, etc.

    Looking in the “set_letter” method, that appears to be where you define the first letter of the word to be the tag the term is categorized under. However, when I tried to add a check for is_numeric, it doesn’t seem to work.

    public function set_letter($post_ID, $post) {
    		if ($post->post_type == 'dict-terms') {
    			$lower = mb_strtolower($post->post_title);
    			$one = mb_substr($lower, 0, 1);
    			
          if (is_numeric($one)) {
            $set = wp_set_object_terms($post_id, 'Misc', 'dict-terms-letter');
            wp_update_term($set[0], 'dict-terms-letter', array(
              'name' => mb_strtoupper('Misc')
            ));
          }
          else {
      			$set = wp_set_object_terms($post_ID, $one, 'dict-terms-letter');
      			wp_update_term($set[0], 'dict-terms-letter', array(
      				'name' => mb_strtoupper($one),
      			));
          }
    		}
    		
    		return;
    	}
Viewing 1 replies (of 1 total)
  • Plugin Author Somonator

    (@somonator)

    Hello! Your code is working, the error in the variable name is $ post_ID, you have $ post_id. Sorry for the long answer.

Viewing 1 replies (of 1 total)
  • The topic ‘Use custom tag for numeric entries’ is closed to new replies.