Skip Navigation

[Resolved] cred_generic_field populated by view stopped working after upgrade

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

This topic contains 2 replies, has 2 voices.

Last updated by nabils 2 years, 4 months ago.

Author
Posts
#2383583

Dear,
I have a form where a generic select is populated by a view. It has been working for years. After upgrade of Toolset plugins, the select field stopped working. I checked similar tickets but didn't help.
here my form's code:
...
[cred_generic_field type='select' field='prof1']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="tl-list-dep-staff" ]]
}
...

and here my view tl-list-dep-staff:
[hide-it][wpv-layout-start][/hide-it]
[wpv-items-found]
<!-- wpv-loop-start -->
<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>
<!-- wpv-loop-end -->
[/wpv-items-found]
[hide-it][wpv-layout-end][/hide-it]

with:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}

I also tried to remove the [hide-it]...[/hide-it] and use the filter but in vain:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
if ($id = '92518') {
$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;
}

Your help is appreciated.

Nabil

#2383613

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I just answered a similar question where someone was asking about how to set this up, so I went through the steps on my own test site to make sure everything was working, and it does with the current plugin versions and latest WP.

I don't know why it might have stopped working on your site, but I suggest you go through the same steps to set it up again. (From what you've shared it looks like this may have been set up a very long time ago.)

The process is very sensitive to any unexpected white space in the View output, which can easily break things.

When you create the View, you must use the Loop Wizard to generate the markup for the output, choosing the List with Separators option. Choose to add any dummy field to the output (e.g. post title).

Then, when the wizard completes, edit the output section to replace the shortcode to output the dummy field with that required to produce the JSON options. In my case the result was the following:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
			[wpv-item index=other]
				{"value":"[wpv-post-id]","label":"[wpv-post-title]"},
			[wpv-item index=last]
				{"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]

You don't need any custom shortcodes or custom code using filters, the above should work.

#2383823

My issue is resolved now. Thank you!