1

I've searched in previous posted questions but I can't find something similar (but if it's already posted, please let me know). I've got the following repeated group of fields, with a select in it:

$social_group_field_id = $social_options->add_field(array(
'id' => $prefix . 'social_network', 
'type' => 'group',
'description' => esc_html__('Add items and insert the URLs of your social media pages', 'my-theme-text-domain'),
'options' => array(
    'group_title' => esc_html__('Social media {#}', 'my-theme-text-domain'),
    'add_button' => esc_html__('Add social media', 'my-theme-text-domain'),
    'remove_button' => esc_html__('Remove social media', 'my-theme-text-domain'),
    'sortable' => true,
    'closed' => true, // true to have the groups closed by default
    'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'my-theme-text-domain' ),
),
));
$social_options->add_group_field($social_group_field_id, array(
'id' => $prefix . 'social_media_select',
'name' => esc_html__('Choose social media', 'my-theme-text-domain'),
'description' => esc_html__('Choose the social media include', 'my-theme-text-domain'),
'type' => 'select',
'show_option_none' => true,
'default' => 'custom',
'options_cb' => 'socialmedia_options',
));
$social_options->add_group_field($social_group_field_id, array(
'id' => $prefix . 'social_media_url',
'name' => esc_html__('URL', 'my-theme-text-domain'),
'description' => esc_html__('Write your URL for the social media selected above', 'my-theme-text-domain'),
'type' => 'text_url',));

What I'm trying to do is to offer a selection of social media to choose, with a select with a list of the main social media networks and a input text field to write the associated profile URL. The select options comes from an array inside an external "socialmedia_options" function retrieved by the options_cb:

function socialmedia_options() {
return array(
...
    'name-of the social' => __('Name of the social', 'my-theme-text-domain'),
...
);}

Now I'd like to output a list of links, cycling the results based on the repeated group created and the relative selected options in it.

Is it possible, or it's the wrong strategy?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.