Skip Navigation

[Resolved] Distance search based on addresses in repeater fields.

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1140758

I am trying to:
Create a view to filter a list of companies. Each company could potentially have multiple addresses which are stored in repeater fields.

Link to a page where the issue can be seen: hidden link

I expected to see:
The ability to search a City or Zip and see any company within xx miles.

Instead, I got:
No items found ;-(

#1141174

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The addresses are stored in repeating fields or repeatable field groups?

If you have an address field where you can enter multiple instances, then each address is stored as normal post meta for the post in question.

In that case if you create a radius search around some location, the post will be returned in the search results if any one of the addresses falls within the radius.

Repeatable Field Groups work differently. Each instance of a group of fields needs a container to group them together, and this is implemented using child posts, meaning that an address which is part of a repeatable field group is not stored against the post itself, but stored against a child post.

Filtering by fields of related posts is not supported yet, although it is coming.

So if you try to search companies based upon an address which is not actually saved against the company posts then you won't get any results, which is what I suspect is happening here.

Your options are to either store the addresses as individual fields (which can repeat), or to create a View where the content being searched is not the company posts, but is the repeatable field group in question.

You will then be looping over the matching repeatable field groups, but you will probably want to display fields from the linked company post, too, and you can mix fields from the company post and the repeatable field group (i.e. the address itself).

Let me know if you need help with that.

#1141365

Thanks for the quick response Nigel.

So I have created a new view here hidden link

What is the best way to show the Parent company name along with each location address as well as the parent company category?

#1141387

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Are these an actual parent-child relationship, or a de facto parent-child relationship arising from adding repeatable field groups?

With an actual parent-child relationship, whenever you insert a field using the Fields and Views button, you should see a post selection tab, where you can specify which post should be the source for the field. Normally this would be the current post, but you can specify that a related post (e.g. parent post) should be the source, and that would add an item attribute to the field shortcode, something like:

[wpv-post-title item='@relationship-slug.parent']

Now, although repeatable field groups are the same as parent-child relationships under the hood, the post selection tab is missing the option to specify that the source post should be the post to which this repeatable field group belongs. (It's an unintended omission and we have an internal ticket to fix it.)

But you can still manually add the item attribute (change "relationship-slug" to the slug of your repeatable field group), so use the Fields and Views button to insert whatever fields you want to display (e.g. the title) and then add the item attribute. If you don't add the item attribute, you'll just be outputting a field of the repeatable field group (e.g. the address itself).