Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $cat = 5;
- $args = array(
- 'category' => $cat,
- 'posts_per_page' => -1,
- );
- $cat_args = array(
- 'child_of' => $cat,
- 'hide_empty' => false,
- );
- $posts_array = get_posts( $args );
- $categories = get_categories( $cat_args );
- foreach ($posts_array as $single_post ){
- $first_letter = mb_substr($single_post->post_title,0,1);
- foreach ($categories as $single_cat){
- if ($first_letter == $single_cat->name){
- wp_set_post_categories($single_post->ID,$single_cat->term_id);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment