Support

Account

Home Forums General Issues Populate Dropdown with Custom Field Values from a custom post type and autofill

Solving

Populate Dropdown with Custom Field Values from a custom post type and autofill

  • Hello!
    If I make a custom post type ‘venues’ populated with custom fields for ‘name/address/email/phone’, can I then create a custom fields form with a select dropdown with the venue name values from the ‘venues’ cpt – that then autofill’s the venue details?

  • Oh and thank you for any help!

    Pritpal

  • Hi @swayoftheverses

    I’m not sure I understand your query, so please forgive me if I’m wrong.

    I believe you should be able to do it. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/. But instead of getting the choices from a text area, you need to populate it from the custom post types.

    That being said, I suggest you use the post object field instead. This field will allow you to select the post object (custom post type) and create a relationship with it. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/post-object/.

    I hope this helps 🙂

  • Thanks James,
    I looked at the first link before I posted my question, but let me clarify my scenario – I need to have a lot addresses/emails/phone numbers for venues (400 I think), these will be on a page of venues, so this will be my custom post type venues. I have a second page that is going to show listings of events taking place, so when I post up a listing, I’d like to be able to pull the venue information into the ACF from that I’ve created in a dropdown select box so that I don’t have to fill out the information again, as for 20-30 listings a day this will get a little excessive!

  • Hi @swayoftheverses

    You should be able to do it by using the post object field. You can also modify the text so it shows the complete address if you want to. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acf-fields-post_object-result/.

    Hope this helps 🙂

  • Cheers,
    I’ll give it go!

  • Hi James,

    I’ve managed to get part 1 done, which is pull the venue title into a dropdown in the events custom field group, how do I autofill the telephone/website/other info custom fields when I select from the dropdown? I just don’t get it!

    Thanks

  • Hi @acf-support James,

    I’ve managed to get part 1 done, which is pull the venue title into a dropdown in the events custom field group, how do I autofill the telephone/website/other info custom fields when I select from the dropdown? I just don’t get it!

    Thanks

  • Hi @swayoftheverses

    With the post object field, you need to add the extra information on the venue custom post type instead. That way, you only need to select the venue post and don’t need to fill the other information when you are selecting the venue post.

    To make the selection showing the required information, you can use the acf/fields/post_object/result filter to replace the venue post title in the selection with the extra information.

    I hope this makes sense 🙂

  • Hi @acf-support

    I worked it all out. I created a post object field called Venue in Events, that pulled in all the different Venues; I just needed to select the appropriate venue and then used the_field() to pull in all the other data from the Venues table that I needed into the template file for the event listing, meaning that I didn’t need to autofill anything in the form, . It all worked out in the end! Although, the documentation is a little confusing at times and a few real-life working examples would be really helpful!

    Thank you!

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Populate Dropdown with Custom Field Values from a custom post type and autofill’ is closed to new replies.