I am trying to use a view shortcode in a CRED generic select dropdown. I am just getting a blank space in the form.
I am pretty sure it's do to the <!-- wpv-loop-start --> markup in the view, but If i delete it, I get an error from Views saying it can't be saved without the markup. So is there a way around it?
View code
[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]
CRED code
[cred_generic_field field='_wpcf_belongs_vendor_id' type='select' class='' urlparam='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":[],
"options":[[wpv-view name='vendor-parent-for-cred-test']]
}
[/cred_generic_field]
Thanks
Dear adam,
Yes, you are right, the shortcode [wpv-layout-start] ... [wpv-layout-end] will produce an extra HTML div tag, which is for Views filters, paginations and ajax feature, and can not be removed, but you can hide it with a custom shortcode, for example the solution in another thread:
https://toolset.com/forums/topic/unable-to-compare-views-output-in-conditional-output/#post-347444
That got rid of any markup, but now I have a bunch of whitespace before and after the JSON markup. So it's still not creating the Select field.
I tried to use a php trim() shortcode around the [wpv-layout-meta-html], but it doesn't seem to work.
Please try this:
1) modify/add the PHP codes in your theme(if you have done this step, you can ignore it)
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
2) modify the Views codes you mentioned above as below, and test again.
[hide-it][wpv-layout-start][/hide-it]
[wpv-items-found]
{"value":"","label":"Choose one"}
<!-- wpv-loop-start --><wpv-loop>, {"value":"[wpv-post-id]","label":"[wpv-post-title]"}</wpv-loop><!-- wpv-loop-end -->
[/wpv-items-found]
[hide-it][wpv-layout-end][/hide-it]
I am still getting whitespace. I changed the view code to 1 line, and that reduced it some, but there is still some present in the picture, and the SELECT doesn't render at all.
I am outputing the VIEW below the [generic_field] just so I can see the output.
[hide-it][wpv-layout-start][/hide-it][wpv-items-found]{"value":"","label":"Choose one"}<!-- wpv-loop-start --><wpv-loop>, {"value":"[wpv-post-id]","label":"[wpv-post-title]"}</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][hide-it][wpv-layout-end][/hide-it]
Since it needs custom codes, provide a live website with same problem, and fill below private detail box with login details, also point out the problem page URL and CRED form URL, I need a live website to test and debug, thanks