How to retrieve both keys and values from an callback function array used in a s
-
Hello,
I’ve got an option page (with option_key => ‘social_options’) that include a select field inside a repeated group ($social_group); btw, the group also include a social_media_url text_url field:This is the select:
$social_options->add_group_field($social_group, array( 'id' => $prefix . 'social_media_select', 'name' => esc_html__('Choose social media', 'text_domain'), 'description' => esc_html__('Choose the social media include', 'text_domain'), 'type' => 'select', 'show_option_none' => true, 'default' => 'custom', 'options_cb' => 'socialmedia_options' ));
It callbacks a function containing the list of social media:
function socialmedia_options() { return array( 'facebook' => __('Facebook', 'text_domain'), ... ); }
In my template I’ve got the following:
$social_data = get_option( social_options', array() ); if ( ! empty( $social_data['social_network'] ) ) { echo "<ul>"; foreach ( $social_data['social_network'] as $social ) { $social_list_item = '<li><a href="'; $social_list_item .= $social['social_media_url']; $social_list_item .= '" title="'; $social_list_item .= $social['social_media_select']; $social_list_item .= '" target="_blank"><i class="fab fa-'; $social_list_item .= $social['social_media_select']; $social_list_item .= '"></i></a></li>'; echo $social_list_item; } echo "</ul>"; }
This is what I get:
<ul> <li><a href="#" title="facebook" target="_blank"><i class="fab fa-facebook"></i></a></li> ... </ul>
What I’d like to get as well is the value of the socialmedia_options() callback function, in order to get the names of the social media, as follow:
<ul> <li><a href="#" title="facebook" target="_blank"><i class="fab fa-facebook"></i> Facebook</a></li> ... </ul>
Any help is more than welcome
Cheers
Paolo
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to retrieve both keys and values from an callback function array used in a s’ is closed to new replies.