Skip Navigation

[Resolved] Views inside a cred generic field

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
- 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 2 replies, has 2 voices.

Last updated by Pat 7 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#493006

Pat

Hello,

I have a Cred and wants to use a Views to define the select options for a generic field. Here is my code :

[cred_generic_field field='port-dattache' post='product' type='select' value='' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[{"value":"","label":"Choisissez le port"}, [wpv-view name="liste-des-ports"]]
}
[/cred_generic_field]

With this code, nothing is displayed. Now, if I replace the Views with the Views result, then, this is working fine. Here the code for this :

[cred_generic_field field='port-dattache' post='product' type='select' value='' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[{"value":"","label":"Choisissez le port"}, {"value":"Carquelane","label":"Carquelane"} ,{"value":"Cannes","label":"Cannes"} ,{"value":"Antibes","label":"Antibes"}]
}
[/cred_generic_field]

I have also checked that the Views result is exactly this :
{"value":"Carquelane","label":"Carquelane"} ,{"value":"Cannes","label":"Cannes"} ,{"value":"Antibes","label":"Antibes"}

Here is the Views code :
<wpv-loop>
[wpv-item index=1]{"value":"[wpv-post-title]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-title]","label":"[wpv-post-title]"}
</wpv-loop>

Any idea on how this should works. For info, I have already used this kind of Cred selection using a Views in another site and this was working. So, I'm not sure if I miss something or Toolset has made some evolution in the code?

Regards
Pat

#493023

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please try to add following code to your 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 == '123' ) {
        $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;
}

Please replace 123 with the problem view's ID, and test again.

#493027

Pat

Hi Minesh,

Thanks a lot, that solved my issue.
Can you explain a little more and tell me if this is something that will be covered by a new version of Toolset plugins?
Regards
Pat

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