Tell us what you are trying to do?
I'm trying to use the get options from shortcode feature with a generic select field to fill the select options with values from one of my custom post types. I have validated that my shortcode is returning valid JSON yet the select field on the form is empty.
Is there any documentation that you are following?
I have reviewed similar tickets on this topic but have not found one that matches my situation. I am not using a View, simply my own PHP code in the shortcode.
Is there a similar example that we can see?
Here is the code for the field on the form:
<label for="%%FORM_ID%%_five-faves">[cred_i18n name='five-faves-label']My Faves[/cred_i18n]</label>
[cred_generic_field type='select' field='five-faves']
{
"required":0,
"options":[ [bman-fave-courses-select-shortcode] ]
}
[/cred_generic_field]
</div>
And here is the code from my custom shortcode:
$courselist = new WP_Query( $args );
while ( $courselist->have_posts() ){
$courselist->the_post();
$data[] = array('value' => get_post_field( 'post_name', get_the_ID() ), 'label' => get_the_title() );
}
wp_reset_postdata();
// save the output in the database for debugging purposes
update_post_meta(14867, "bmantest", json_encode($data));
// return the them in json format for the generic field
return(json_encode($data));
Notice that I save the returned output in the database to help with debugging. I have validated that output as valid JSON. Here's a sample of it (too long to paste the entire output here) showing the first two entries and the last two entries:
[{"value":"birkdale-golf-club","label":"Birkdale Golf Club"},{"value":"carolina-lakes-golf-club","label":"Carolina Lakes Golf Club"},
...
{"value":"warrior-golf-club","label":"Warrior Golf Club"},{"value":"waterford-golf-club","label":"Waterford Golf Club"}]
And finally, here is the HTML output that is generated on the front end when I test the form:
<label for="cred_user_form_14872_1_1_five-faves">My Faves</label>
<div class="js-wpt-field-items js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="select-five-faves">
<select id="cred_user_form_14872_1_1_five-faves" class=" wpt-form-select form-select select" preset_value="" cred_generic="1" placeholder="" preview="" previewsize="" urlparam="" data-wpt-type="select" name="five-faves">
<option value="" class="wpt-form-option form-option option" data-wpt-type="option" data-wpt-id="cred_user_form_14872_1_1_cred_user_form_14872_1_1_five-faves" data-wpt-name="five-faves" selected="selected">--- not set ---</option>
</select>
What is the link to your site?