Guest User

Untitled

a guest
Dec 10th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. $cat = 5;
  2.  
  3. $args = array(
  4.     'category' => $cat,
  5.     'posts_per_page' => -1,
  6. );
  7.  
  8. $cat_args = array(
  9.     'child_of' => $cat,
  10.     'hide_empty' => false,
  11. );
  12.  
  13. $posts_array = get_posts( $args );
  14.  
  15. $categories = get_categories( $cat_args  );
  16.  
  17. foreach ($posts_array as $single_post ){
  18.     $first_letter = mb_substr($single_post->post_title,0,1);
  19.     foreach ($categories as $single_cat){
  20.         if ($first_letter == $single_cat->name){
  21.             wp_set_post_categories($single_post->ID,$single_cat->term_id);
  22.         }            
  23.     }  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment