Advertisement
arie_cristianD

custom fields primary category

Feb 3rd, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. add_action( 'save_post', 'custom_jnews_parimary_cat', 100 );
  2. add_action( 'edit_post', 'custom_jnews_parimary_cat', 100 );
  3.  
  4. function custom_jnews_parimary_cat( $post_id ) {
  5.     if ( isset( $_POST['acf'] ) ) {
  6.         $jnews_primary_category = array();
  7.         if ( ! empty( $_POST['acf']['field_67a179e3b2922'] ) ) { /* change field_67a179e3b2922 with your Primary Category Fields Key */
  8.             $jnews_primary_category['id'] = $_POST['acf']['field_67a179e3b2922'];
  9.         }
  10.  
  11.         if ( ! empty( $_POST['acf']['field_67a18042776b6'] ) && is_array( $_POST['acf']['field_67a18042776b6'] ) ) {  /* change field_67a18042776b6 with your Hide Category Fields Key */
  12.             $jnews_primary_category['hide'] = implode( ',', $_POST['acf']['field_67a18042776b6'] );
  13.         }
  14.  
  15.         if ( ! empty( $jnews_primary_category ) ) {
  16.             update_post_meta( $post_id, 'jnews_primary_category', $jnews_primary_category );
  17.         }
  18.     }
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement