Created
October 18, 2023 10:34
-
-
Save wbcomdev/798fbdb78a59cae381ebdfd9e00ac3d9 to your computer and use it in GitHub Desktop.
Add/Display ACF Field Group with Single Business
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Get acf group fields | |
| * | |
| * @return void | |
| */ | |
| function get_acf_group_field() { | |
| $acf_group_fields = acf_get_fields( 'group_652f89c399d0b' );// replace it with group key | |
| return $acf_group_fields; | |
| } | |
| /** | |
| * Display acf group fields in contact tab | |
| * | |
| * @return void | |
| */ | |
| function display_acf_group_fields_in_conatct() { | |
| acf_form_head(); | |
| $get_group_fields = get_acf_group_field(); | |
| $fields = array(); | |
| foreach ( $get_group_fields as $_field ) { | |
| $fields[] = $_field; | |
| } | |
| acf_render_fields( $fields, get_the_ID() ); | |
| } | |
| add_action( 'business_profile_after_contact_info', 'display_acf_group_fields_in_conatct' ); | |
| /** | |
| * Save acf taxonomy fields | |
| * | |
| * @param mixed $post | |
| * @return void | |
| */ | |
| function save_taxonomy_fields( $bp_business_id ) { | |
| $get_group_fields = get_acf_group_field();// replace it with group key | |
| foreach ( $get_group_fields as $get_group_field ) { | |
| if ( isset( $_POST['acf'] ) && ! empty( $_POST['acf'] ) ) { | |
| foreach ( $_POST['acf'] as $acf_fields ) { | |
| wp_set_post_terms( $bp_business_id, $acf_fields, $get_group_field['taxonomy'], false ); | |
| } | |
| } | |
| } | |
| } | |
| add_action( 'bp_business_after_save_business_setting', 'save_taxonomy_fields', 99, 1 ); | |
| /** | |
| * Show Business taxonomy | |
| * | |
| * @return void | |
| */ | |
| function show_taxonomy_in_about_section() { | |
| $get_group_fields = get_acf_group_field(); | |
| foreach ( $get_group_fields as $get_group_field ) { | |
| $get_terms = get_the_terms( get_the_ID(), $get_group_field['taxonomy'] ); | |
| if ( ! empty( $get_terms ) ) { | |
| ?> | |
| <h2><?php echo 'Display' . ' ' . $get_group_field['label'] . ' ' . 'Taxonomy'; ?></h2> | |
| <?php | |
| foreach ( $get_terms as $get_term ) { | |
| ?> | |
| <ul> | |
| <li> <?php echo esc_html( $get_term->name ); ?> </li> | |
| </ul> | |
| <?php | |
| } | |
| } | |
| } | |
| } | |
| add_action( 'bp_business_profile_after_render_contact_info', 'show_taxonomy_in_about_section' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment