Tell us what you are trying to do?
I am trying to create a dropdown on a CRED form that displays a list of post titles (Post type: Item), and saves the post id to a field in another post type (Post type: Accessories)
Is there any documentation that you are following?
I am trying to follow the instructions here: https://toolset.com/forums/topic/cred-form-dropdown-with-custom-posts/
I have created a view (items-for-dropdown) with the following output:
[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>[/wpv-no-items-found][wpv-layout-end]
In that ticket it says to make sure the output is in JSON format. Not sure if this is correct? If not, how do I output in JSON?
I have then added the following to functions.php:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
if ( $id == '374' ) { //Please adjust to your Views ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}
And this is my CRED form:
[credform class='cred-form cred-keep-original']
[cred_field field='form_messages' value='' class='alert alert-warning']
<div class="form-group">
<label>item Parent</label>
[cred_field field='_wpcf_belongs_item_id' value='' select_text='--- not set ---' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Amount</label>
[cred_field field='amount' post='accessory' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Accessory Item</label>
[cred_generic_field field="accessory-item" type="select" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="items-for-dropdown"] ]
}
[/cred_generic_field]
</div>
[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[/credform]
But as you can see on the link below, nothing is displaying under the label.
Can you see what I've done wrong?
What is the link to your site? hidden link