Home Forums Add-ons Repeater Field Using a repeater field as a relationship custom field


Using a repeater field as a relationship custom field

  • I have a custom post type with custom fields. One of those fields is a repeater.
    The custom post type is a Location and the repeater fields are sub-locations. Example Location = Head Office
    Sub-locations = Goods Entrance, Reception Desk, Kitchen

    Because each sublocation is unique to the location and have additional fields such as directions and an annotated map I chose to use repeater rather than taxonomy since “Reception Desk” at location 1 would have nothing to do with “Reception Desk” at location 2.

    The repeater field works great for storing and displaying the information but I now have another custom content type which has a post object field for choosing the location. This works but I also need to choose the specific sub location. Can this be done?

  • Hi,

    Why don’t you make a Location as a hierarchal custom post type so when you create a Sub-location you set a Location as a parent.

    In that case you can set any location or sub-location in another custom post type through post object field.

  • That was my plan B – the problem is it is a workflow issue as it is a complex system and could result in many content types so the admin would need to go into 6+ content types and create items to create what they want so attempting to minimise.

    I had an alternative I am testing where I add one of the fields for the repeater sub-location as a taxonomy and have that serve as an ID for the sub location. I would then be able to select that taxonomy item from the other custom post type and know which of the sublocations was required. However, even if “create new items” is ticked for the taxonomy field there is no way to create new terms on the fly as the field options are only select/radio/checkboxes.

    I will sleep on it but I think I will admit defeat and go for @rumo suggestion and just make a new custom post type.

  • I have 2 examples here that if you use some of the ideas from both you could do this. One of the examples is how to populate a select field base on another select field and the other is how to populate fields based on a selection in a relationship field

    A post object field and a relationship field are similar, although you may need to do some work to get that working. You can use either example for the AJAX portion, the main difference is that you’re going to be getting values from the repeater in the “Location” post to populate the second select field. Or you can go with just the 2 select field option and populate the fist field the same way that the example shows and the second field from the repeater.

    This is actually another good example that I will put together if I have time. “Populate a select field from a repeater based on the selection of a post object field”

  • AMAZING – this solves my next 2-3 challenges as well. Thank you very much.

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

The topic ‘Using a repeater field as a relationship custom field’ is closed to new replies.