Skip Navigation

[Resolved] Populating a CRED form field with data from other posts

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

Last updated by Eko Wid 3 years ago.

Author
Posts
#2382643

Tell us what you are trying to do?
I have two post types (Journal and People). I want to populate CRED on Journal form with data from People CPT.

Here's the wpv-loop from my custom view display-people-list. Used to display the options in the CRED form
<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>

Here's the code for the multiselect field name in my CRED form:
[cred_generic_field type='multiselect' field='name']
{
"required":0,
"default":[],
"options":[[wpv-view name="display-people-list"]],
"persist":1
}
[/cred_generic_field]

and nothing show on name field.

Is there any documentation that you are following?
https://toolset.com/forums/topic/populating-a-cred-form-field-with-data-from-other-posts-besides-taxonomy/

Is there a similar example that we can see?

What is the link to your site?
hidden link

Thank you

#2383609

Nigel
Supporter

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

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

Hi there

It is very temperamental using a View to populate the options of a form generic field, unexpected white space can easily break the process, and I suspect that is what is happening in your case.

I just went through the steps again on my own site to confirm it should be working, which it did.

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]

It should then work.

#2383625
Screenshot 2022-06-13 164220.png
Screenshot 2022-06-13 164235.png

Hi Nigel,

Thank you for your help. Unfortunately it still not working on me.

#2383669

Nigel
Supporter

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

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

You ran the Loop Wizard rather than copying and pasting the markup I shared?

If so, last thing to check, when you use the Form editor UI to insert the generic field where the options come from a shortcode, there are spaces between the square brackets which are missing according to your screenshot.

I'm not sure if that could be a problem, but it is one more thing to eliminate, i.e.

"options":[ [wpv-view name="Display People List"] ]
#2383671

My issue is resolved now. Missing spaces between the square brackets was the problem.
Thank you!