Advertisement
arie_cristianD

update auto primary category with FSV Frankfurt

Jan 4th, 2024 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. add_action(
  2.     'jnews_single_post_begin',
  3.     function () {
  4.         $parimary_cat = get_post_meta( get_the_ID(), 'jnews_primary_category', true );
  5.         if ( empty( $parimary_cat['ID'] ) ) {
  6.             $categories = get_the_category( get_the_ID() );
  7.             foreach ( $categories as $category ) {
  8.                 //change the gaming with your category FSV Frankfurt slug
  9.                 if ( 'gaming' === $category->slug ) {
  10.                     update_post_meta( get_the_ID(), 'jnews_primary_category', array( 'id' => (int) $category->cat_ID ) );
  11.                 }
  12.             }
  13.         }
  14.     }
  15. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement