Skip Navigation

[Resolved] Populate SELECT with a names (loop) from CPT

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

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 15 replies, has 3 voices.

Last updated by Christian Cox 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1446751

Hello!
I have One cpt named "Bookings"
I have one called "Trips"
In "trips" i adding around 10 posts
And in the post form for Bookings i like to have a Select with all the trips in it.
i cant find any solution for this or im seeking to bad 🙂

#1446867

Im sorry, i had to leave my screen 🙂

Will the options be saved ?
I will check this in a bit. Ill get back soon.

#1446971
img3.JPG
img2.JPG
img1.JPG

I did try this now.
and i get just a bit on the way. I tried the Radiobutton as in the support ticket you showed.
and the output value seems to be correct. but the radiobuttons is not showing.

the view: img1

the output: img2

the form: img3

and i did "Disable the wrapping DIV around the View "

#1447561

Hi, that's odd, your code all looks good to me.
- Is your Toolset software up-to-date?
- Is there any extra content in the View's Output Editor panel? If you cannot see the Output Editor panel, scroll to the top right and click "Screen Options" to activate the Output Editor panel. The contents should be only:

[wpv-filter-meta-html]
[wpv-layout-meta-html]

- If you hard-code the values does the generic field show up as expected?

[cred_generic_field type='radio' field='test' class='test']
{
"required":1,
"default":[],
"options":[{"value":"347","label":"Package 2"},{"value":"346","label":"Package 1"}]
}
[/cred_generic_field]

I may need to take a closer look. Please provide login credentials in the private fields here so I can take a closer look.

#1448847

"Disable the wrapping div around the View" must be checked - sorry I misunderstood your comment earlier. I checked the checkbox and now the radio field appears as expected. Can you confirm this is working as expected now?

#1451007
not set.JPG

I also missunderstood the guide... my bad!!

A question thou
how can i change the "--not set--" in a select and also make the select required?
And how make this be saved into a field ? What i mean that if i use "persist":1
then it is saved but the value is a post-id. i like to save the Name "package 1" instead of "346"
and in a select also i backend as frontend like if i use a select that is not an generic.
do you understand how i mean ? (see next post)

#1451061
123.JPG

This is what i mean about my resent post 🙂

#1455893

Is there any chance you may have time to look at this today (two resent post i replied)
Please 🙂
thanks

#1456207

how can i change the "--not set--" in a select and also make the select required?
You would find the numeric ID of the item you want selected and place that in the "default" option. For example, if you want Package 1 preselected, you would use the ID 346 in the default setting, like this:

[cred_generic_field type='select' field='tripselect']
{
"required":1,
"default":[346],
"options":[ [wpv-view name="trip-select"] ],
"persist":1
}
[/cred_generic_field]

And how make this be saved into a field ? What i mean that if i use "persist":1
then it is saved but the value is a post-id. i like to save the Name "package 1" instead of "346"
and in a select also i backend as frontend like if i use a select that is not an generic.
There is no simple way to make a select field in the backend that has options populated by a View, or populated by all the posts in some post type. This is why you must use a generic field on the front-end of the site. The best way to save the value is to use a simple text field. Also I recommend you save the post ID, not the post title. The post title can change later, but the post ID will remain constant. Is there a specific reason you want to save the title instead of the ID?

If you insist on saving the post title instead of post ID, you must change the View and replace [wpv-post-id] with [wpv-post-title]

#1456681

hello and thanks for your replay.

yes there is a specific reson why i want to save the name instead of ID. 🙂

In admin in the booking this form does ist much easier to know what the customer has selected. No one knows what 346 is.
But "package 1" all admins know what that is.

BUT (?)
Maybe i can have a generic select in back end also (?) , that select the id and shows the name instead.
Just like a manuell populated select works in toolset.
I wish to make it as simple as much to handle a booking we do with toolset without manuell populating a select in back end, and this is almost the only thing i have seen not working as smooth as everything else in toolset 🙂
It works really great. Just this last thing with select the trip (package)
so if someone needs to change what package the customer like to change, so is it much easier to change an select (or name) than an ID.

#1456683
img1b.jpg
img1a.JPG

forgot attach in last post

img1a is an manuell populated select. Select the selected value also in back end.
img1b is like the View with persist:1 is saved with an id. and much harder to handle in admin

#1456743

I wish to make it as simple as much to handle a booking we do with toolset without manuell populating a select in back end, and this is almost the only thing i have seen not working as smooth as everything else in toolset
Right, but this is exactly what Toolset's Post Relationships and post reference fields are for. Is there a reason these features will not work in your case? Perhaps I can help you work around problems with those features instead of re-creating these fields manually and using custom code.
https://toolset.com/documentation/post-relationships/

#1458199

Hi again,
ok. im not sure how i set this up.
My scenario is:
Post type: "Resa" (in english: Trip)
Post type "Bokningar" (in english: Bookings)

In this "Resa" i create posts with information about every trip (1.jpg)
As you can see, package 1, package 2 etc...

This i would like to have in a select in the Post form that save data to the post type "Bokningar" (2.jpg)
So the customer can choose the trip, easy.

In admin i like to have the "same" select in the post type "Bokningar" so IF the customer like to change, we can just select another and update.

But when i look in the relastion, i can only see relation from one post type to another.

Am i lost here or what do i miss ? 🙂

#1458201
2.JPG
1.JPG

forgot images...

#1458487

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Patrik,

Christian, is currently out today but will be back tomorrow to continue to help you resolve this issue.

Thank,
Shane