Advertisement
GochiSiyan

set split post for category

Jan 17th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. add_action('wp',function (){
  2. $split_category=[
  3. 'category 1',
  4. 'category 2',
  5. ];
  6.  
  7. $posts = get_posts(
  8. array(
  9. 'numberposts' => -1,
  10. 'post_status' => 'any',
  11. 'post_type' => 'post',
  12. )
  13. );
  14.  
  15. foreach ($posts as $post) {
  16. $meta = get_post_meta($post->ID,'post_split');
  17. $categories=get_the_category($post->ID);
  18. foreach ($categories as $category) {
  19. if (in_array($category->cat_name,$split_category)) {
  20. $meta['enable'] = '1';
  21. update_post_meta($post->ID,'post_split',$meta);
  22. }
  23. }
  24. }
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement