Skip Navigation

[Resolved] How to build a View that populate a CRED generic field, "select"

This support ticket is created 7 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by tinaH 7 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#486772

I am trying to use a View to populate a CRED generic "select" field.

I tested the view on a page and it returns the posts as it should but I don't get nothing in the form.
The field is completely ignored in front end, nothing ...

Added this to the Cred form

[cred_generic_field field='ytor' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[[wpv-view name="spaces-select"]]
}
[/cred_generic_field]

This is my View:

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

This is what I get if I add the View to a Page, so the View it self is working.

<div id="wpv-view-layout-5122-TCPID5123" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-5122-TCPID5123" data-viewnumber="5122-TCPID5123" data-pagination="{"id":"5122","base_permalink":"/?page_id=5123&preview=true&wpv_view_count=5122-TCPID5123&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/?page_id=5123&preview=true&wpv_view_count=5122-TCPID5123">

    
    
    
      {"value":"315","label":"A:12"},
    
      {"value":"316","label":"A:18"},
    
      {"value":"314","label":"B:01"},
    
      {"value":"313","label":"B:11"},
    
      {"value":"312","label":"C:01"},
    
      {"value":"300","label":"C:03"},
    
      {"value":"298","label":"C:16"},
    
      {"value":"800","label":"D:12"},
    
    
    
</div>
#486867

I found in another question that I need to add the code below to my functions.php to make this work.
I don't know php so my question is can I add multiple view ID's, comma separated?
Or, do I have to repeat this code for every View I want the output to be raw/clean?

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

From these tickets:
https://toolset.com/forums/topic/views-result-array-as-shortcode-parameter/page/2/#post-344768
https://toolset.com/forums/topic/views-raw-output/

#486904

Hi,

You can apply the same function to multiple views with PHP function in_array, for example, modify this line from:

if ( $id == '999' ) { //Please adjust to your Views ID

To:

if ( in_array($id, array(999, 123, 456) ) ) { //Please adjust to your Views ID

More help:
hidden link

#487039

Thank you 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.