Skip Navigation

[Resolved] Populate select list with a view

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by stephenW-4 7 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#561801

I am trying to:

populate a select list with a view, the view displays only the posts created by the logged in user

<div class="form-group">
<label>quiz Parent</label>
[cred_generic_field field='_wpcf_belongs_quiz_id' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[[wpv-view name="quizselectlist"]]
}
[/cred_generic_field]
</div>

below is shortcode for the view quizselectlist

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start --><wpv-loop>{"value":"[wpv-post-id]","label":"[wpv-post-title]"},</wpv-loop><!-- wpv-loop-end -->
[/wpv-items-found][wpv-no-items-found][wpml-string context="wpv-views"]No items found[/wpml-string] [/wpv-no-items-found]
[wpv-layout-end]

On the frontend cred form the select box does not appear

The select box does not appear on my form

#561844

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - To generate the clean raw output of JSON string using views you need to add the following code to your current theme's functions.php file.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '9999' ) { //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;
}

Where:
Replace '9999' with your original view ID.

Could you please try to use above solution and try to resolve your issue.

#561897

Hi Minesh,

Thanks for your quick response, unfortunately, this has not resolved the issue. Do you have any suggetions?

best regards

Stephen

#561928

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is strange. I need to check on your install what is going wrong there but before you send me access details I would like to inform you that we just released a new version of CRED plugin. could you please update CRED to 1.9.2. You can download it from:
=> https://toolset.com/download/toolset-cred/#changelog

1)
Please share problem URL.

2)
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#562031

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Indeed - there looks like a possible issue. Please allow me to check with our developers.

Kindly hold on for further updates.

#562191

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I just wanted to update you that the issue has been confirmed and our developers will soon address it. Please hold on for further updates.

#562312

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now. I've updated your view's loop output as given under and now I can see that the dropdown is working.

[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-layout-end]
#564516

Thank you, the select list is now populated with the view. But how do I set the default value of the select list when redirected from the parent form.

I've added the function below but this only works on a Cred field and not a Cred Generic Field

add_filter('cred_success_redirect', 'custom_redirect',10,3);

function custom_redirect($url, $post_id, $form_data)

{


    if ($form_data['id']==26806)
        return '/step2?parent_{quiz}_id='.$post_id;
    return $url;
}
[cred_generic_field field='_wpcf_belongs_quiz_id' value='' type='select' select_text='--- select quiz ---' class='form-control' output='bootstrap' urlparam='' ]
{
"required":1,
"validate_format":0,
"default": [[wpv-post-id id="$quiz"]] ,
"options":[ [wpv-view name="quizselectlist"] ]
}
[/cred_generic_field]
#564518

I've added the urlparam='parent_quiz_id' and this works.

Thanks