Advertisement
arie_cristianD

set default value for AFC group fields

Feb 4th, 2025
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. /**
  2.  * Set default valut for Custom Primary Category Fields.
  3.  */
  4. function set_default_primary_category( $value, $post_id, $field ) {
  5.     if ( empty( $value ) ) {
  6.         $jnews_primary_category = get_post_meta( $post_id, 'jnews_primary_category', true );
  7.         if ( is_array( $jnews_primary_category ) && isset( $jnews_primary_category['id'] ) ) {
  8.             $value = $jnews_primary_category['id'];
  9.         }
  10.     }
  11.     return $value;
  12. }
  13.  
  14. /**
  15.  * Set default valut for Custom Hide Category Fields.
  16.  */
  17. function set_default_hide_category( $value, $post_id, $field ) {
  18.     if ( empty( $value ) ) {
  19.         $jnews_primary_category = get_post_meta( $post_id, 'jnews_primary_category', true );
  20.         if ( is_array( $jnews_primary_category ) && isset( $jnews_primary_category['hide'] ) ) {
  21.             $value = explode( ',', $jnews_primary_category['hide'] );
  22.         }
  23.     }
  24.     return $value;
  25. }
  26.  
  27. add_filter( 'acf/load_value/name=custom_primary_category', 'set_default_primary_category', 10, 3 );
  28. add_filter( 'acf/load_value/name=custom_hide_category', 'set_default_hide_category', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement