Support

Account

Home Forums General Issues Displaying items within a CPT as Choices in Repeater for another

Solved

Displaying items within a CPT as Choices in Repeater for another

  • I have the following setup in WordPress:

    A custom post type for Projects, which contain individual projects. For each project there is a repeater field, allowing one to add image samples.

    Example:

    Projects

    • Project 1
      • Sample 1.1
      • Sample 1.2
      • Sample 1.3
    • Project 2
      • Sample 2.1
      • Sample 2.2
      • Sample 2.3
    • Project 3
      • Sample 3.1
      • Sample 3.2

    A new custom post type is being created – called “Pitches” – that will contain individual pitches. For each pitch there is a repeater field. The idea is to allow one to add image samples from other projects (noted above).

    An example scenario would be the following:

    Pitches

    • Pitch 1
      • Sample 1.2
      • Sample 3.3
      • Sample 2.1
    • Pitch 2
      • Sample 2.2
      • Sample 1.3

    Based on the previous information, my question is this:

    On an individual pitch page, is it possible for each added sample to have an option to choose a specific image from within a particular project?

    For example, add a new image and select Sample 3.3 from Project 3, add another image and choose Sample 1.2 from Project 1.

    Thanks for the help! This one has me a little stumped.

  • Hi @bloom

    Unfortunately, it is not possible to select a custom field value from another post object.

    This would make for a great field type, but it does not yet exist.

  • I was thinking so, too. This helps to confirm that.

    It looks like I have some more homework to do to figure this one out.

    Thanks so much for the help!

  • Actually, I believe what you want to do may be possible. I have run into a similar need.

    In my case I have a custom post type and in that post the user can set the item as either active or inactive. When they select inactive they are then shown a select box where they can select an alternate item to use in its place. I could have used the Post Object or Relationship type field for this, however, this would allow them to select another item that was also inactive. I did not want to do this because it would just confuse them and make them do the work of selecting an active item.

    Then I found this tutorial: Dynamically populate a select field’s choices
    http://www.advancedcustomfields.com/resources/tutorials/dynamically-populate-a-select-fields-choices/

    (sorry for the long link, for some reason the editor would not allow me to add the link the right way.)

    Anyway, the tutorial shows you how to use an options field to populate a select box. However, with a little work I was able to change it to a query to get only the items that are marked as active and built my own select that way. I have found this useful several times with the current project I’m working on.

    You might be able do the something similar but in your case you can create a query that gets a list of the projects and then a loop to pull the list of images in each project. Then your user could select from that. Unfortunately there might be more work because you would only be able to add text to the select field to choose from and I don’t think you can show the actual images in the select field so it may not be a perfect workaround.

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

The topic ‘Displaying items within a CPT as Choices in Repeater for another’ is closed to new replies.