Support Forum
How can I have a dropdown custom field that would then dynamically inject all the data from the custom fields from a certain post type into a post like inserting a reusable part in Oxygen.
So for example.
I have Custom Post Type A and have added custom fields for this post type.
On Custom Post Type B I want to have a drop down where I can choose the post from Custom Post Type A and this would add that data to the post in Custom Post Type.
Sorry if that's confusing but I'm struggling to find a way to describe it!
Hello there,
You might want to use the field post
which supports a dropdown of posts of a certain post type and save the field value as the post ID.
Please read more on the documentation https://docs.metabox.io/fields/post/
Hi Peter, I think I have found another way to achieve what I want. I think I can create a checklist that would allow me to select multiple choices. What I don't understand is how to then retrieve the fields associated with each selection.
So for example:
I have a post type for companies. Each company has three custom fields.
[service] - this is what they do
[company_website] - a url to their webpage
[company_name] - The name of the company
I then add all my companies and create another custom field with a checklist. I see that the checklist has the option to quote:
use a PHP function that returns an array of options, enter callback: function_name.
The callback function must be declared before adding to the box.
So I'd like to know how/if it's possible to retrieve my three custom fields for all my posts in the post type 'companies' and display them as a checkbox list.
Once the items are selected they would display on the front end in a list or similar in the format of
[service]: [company_name]
Do you think this is achievable? Many thanks.
Hello,
So what will display in the checklist? The custom field value from all companies? Can you please create a diagram or specific example for your requirements?
Please notice that, the custom fields are associated with the post. You should not use a field value of a post for another post like that.
We organise events and when we do an event we work with many different suppliers or vendors.
After the event if we blog about it we like to add a list of credits at the end of the post mentioning each person or company, what they did and linking to their website.
I have a custom post type called "Real Weddings" - this is the post type where we write the blog posts about the events and need to give credit to the vendors involved.
I have also created the custom post type called "Vendors"
I have created three custom fields for this post type:
Vendor's Role has the id of vendor_role
Vendor's Name has the id of vendor_name
Vendor's Link has the id of vendor_link
Example data for these fields for a vendor would be:
Vendor's Role: Florist
Vendor's Name: Special Flowers
Vendor's Link: there URL goes here
This information would then be displayed on the Real Wedding post template:
Florist: < a href="vendor_link" />Special Flowers
I have created a field group called "Select Vendors for Credit List" and have added a custom field called "Select Vendors".
Field Group id: vendor-credits
Custom field id: select_vendors
For this field I have chosen the type as checkbox list.
I have set the field to show only on the post type of "Real Weddings".
I want to be able to select the vendors that worked on each event from the checkbox list that will be available on the post type "Real Weddings".
Currently I can see on my Real Wedding post type:
NB. The options shows in this screenshot are just dummy data. I have not been able to callback the actual data I require.
So my first questions is:
How do I query the "Vendor" custom post type to retrieve the actual data I need and have it display as the options for my checkbox list?
On the checkbox list custom field it says:
> To use a PHP function that returns an array of options, enter callback: function_name.
> The callback function must be declared before adding to the box.
I do not know php at all. So I need help to create a function that queries the "vendor" post type and returns the values correct?
Here is a screenshot of the checkbox list I created. So my understanding is that I need to dynamically populate the 'choices' field. Here I have just added some dummy data but I need a function.
and secondly:
Would I then be able to use a repeater to query the "Real Wedding" post type and only display the vendors that have been selected as having worked on this event?
PS. I am using Oxygen Builder.
We organise events and when we do an event we work with many different suppliers or vendors.
After the event if we blog about it we like to add a list of credits at the end of the post mentioning each person or company, what they did and linking to their website.
I have a custom post type called "Real Weddings" - this is the post type where we write the blog posts about the events and need to give credit to the vendors involved.
I have also created the custom post type called "Vendors"
I have created three custom fields for this post type:
Vendor's Role has the id of vendor_role
Vendor's Name has the id of vendor_name
Vendor's Link has the id of vendor_link
Example data for these fields for a vendor would be:
Vendor's Role: Florist
Vendor's Name: Special Flowers
Vendor's Link: there URL goes here
This information would then be displayed on the Real Wedding post template:
Florist: < a href="vendor_link" />Special Flowers
I have created a field group called "Select Vendors for Credit List" and have added a custom field called "Select Vendors".
Field Group id: vendor-credits
Custom field id: select_vendors
For this field I have chosen the type as checkbox list.
I have set the field to show only on the post type of "Real Weddings".
I want to be able to select the vendors that worked on each event from the checkbox list that will be available on the post type "Real Weddings".
Currently I can see on my Real Wedding post type:
NB. The options shows in this screenshot are just dummy data. I have not been able to callback the actual data I require.
So my first questions is:
How do I query the "Vendor" custom post type to retrieve the actual data I need and have it display as the options for my checkbox list?
On the checkbox list custom field it says:
> To use a PHP function that returns an array of options, enter callback: function_name.
> The callback function must be declared before adding to the box.
I do not know php at all. So I need help to create a function that queries the "vendor" post type and returns the values correct?
Here is a screenshot of the checkbox list I created. So my understanding is that I need to dynamically populate the 'choices' field.
and secondly:
Would I then be able to use a repeater to query the "Real Wedding" post type and only display the vendors that have been selected as having worked on this event?
Sorry for the double post but couldn't get the images to work first time...
I have managed to achieve what I wanted using Relationships. Thanks for the responses.
Hello,
Thanks for your details. I understand the requirements.
So in this case, you can use the field post or use the extension MB Relationships to display a list of vendors when editing a wedding. Then based on the vendor (post) ID, you can get the field value (vendor_name) of the vendor and display it on the wedding post (frontend).
Please read more on the documentation https://docs.metabox.io/fields/post/#data
https://docs.metabox.io/extensions/mb-relationships/
If you are not familiar with coding, you can create a customization service request with an extra fee, our development team will help you to do that. Please submit the request here https://metabox.io/contact/