SHARE
TWEET

Untitled

a guest Jun 15th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GOOD domain/cartoon-series/<series-name1>/episodes/<episode-name>  
  2. GOOD domain/cartoon-series/<series-name2>/episodes/<episode-name>  
  3. BAD  domain/cartoon-series/<series-name2>/episodes-1/<episode-name>
  4.      
  5. //Automatically creates a category in the case log and adds it to the post.
  6.  
  7. function add_title_as_category( $postid ) {
  8. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
  9.    $post = get_post($postid);
  10. if ( $post->post_type == 'case') { // change 'post' to any cpt you want to target
  11.     $term = get_term_by('slug', $post->post_name, 'case-log');
  12. if ( empty($term) ) {
  13.   $add = wp_insert_term( $post->post_title, 'case-log', array('slug'=> $post->post_name) );
  14.   if ( is_array($add) && isset($add['term_id']) ) {
  15.     wp_set_object_terms($postid, $add['term_id'], 'case-log', true );
  16.   }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top