Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 10th, 2012  |  syntax: PHP  |  size: 0.61 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add_action('save_post', 'set_dictionary_terms');
  2.  
  3. function set_dictionary_terms($post_ID) {
  4.     $title = get_the_title($post_ID);
  5.     $first_letter = strtolower(substr($title, 0, 1));
  6.    
  7.     if ( get_post_type($post_ID) == 'dictionary' ) {
  8.    
  9.          wp_set_object_terms( $post_ID, $first_letter, 'mydictionary' );
  10.     }
  11. }
  12.  
  13. // Works perfectly for all standard letters excepting exotic ones like Ą, Ż, Ź etc. (I've already created terms for them, the slugs for them are like a-2, z-2, z-3 etc., tried something like if($first_letter == "ą") { $first_letter = "a-2" }; but doesn't work either, any ideas?
clone this paste RAW Paste Data