Beee4life / acf-city-selector

An ACF extension to create a new field type, where you can select a city based on country and provence/state.
37 stars 15 forks source link

Custom post type archives based on city selector fields #102

Open karlsan opened 2 years ago

karlsan commented 2 years ago

Hello, thanks for the interesting plugin. We are moving a site from Drupal to WordPress and were searching for the plugin functionality - being able to select country > region > city.

We have a directory of clubs (a custom post type). The URL structure is:

website.com/clubs/post

We'd also like visitors to be able to find clubs based on country / region / city, with archive pages like this:

website.com/clubs/germany website.com/clubs/germany/brandenburg website.com/clubs/germany/brandenburg/potsdam

If a visitor clicks on the first link, they'll see all clubs in Germany; if they click on the second, they'll see all clubs in Brandenburg and so on.

Looking at the documentation I didn't find anything about this, but based on issues #100 and #85, it sounds like this is not possible with the plugin?

I have been reading about how to create custom permalinks containing custom fields, but haven't found anything about how to create archive pages based on custom fields. Perhaps it's not possible. The plugin is great and UI very easy to use, but it sounds like we will have to use native WordPress hierarchical taxonomies instead.

Beee4life commented 2 years ago

This plugin is not meant to filter posts, but to add a location (as a meta value) to a post. To determine that location, you can use my field to narrow down your selection.

You can create your own archive pages. That has nothing to do with my plugin. Just create rewrites.

karlsan commented 2 years ago

Thanks, I get that its purpose isn't to filter posts, but to add the location custom field(s). And it does that very well, it's a great plugin!

In our case, it's important to have a location archive. I couldn't figure out how to achieve this with WordPress rewrites and custom fields, or if it would be efficient.

So for now, we will most likely use a custom hierarchical taxonomy instead, where we can easily get:

website.com/clubs/germany website.com/clubs/germany/brandenburg website.com/clubs/germany/brandenburg/potsdam

and then I'll have to see if there's a way of making this taxonomy use conditional selects, similar to how your custom field setup works.

Beee4life commented 2 years ago

Then I might have misunderstood...

If you know how to add the location to a post, then your question is more related on how to create a custom archive, with the meta data from the posts, which is nothing more than an extended wp_query.

So first make sure this archive works, by either creating a custom rewrite. Then with pre_get_posts you can query the content.

karlsan commented 2 years ago

Hm, I'm still not sure if I misunderstand or it's possible to do what I'm after. I can create a page and run a custom wp_query and then filter for specific city/region/country custom fields. That's fine for specific cases. But if having dozens of countries, hundreds of regions and thousands of cities, I'm not sure if it can be automated?

With hierarchical taxonomies I can just create a custom taxonomy for my custom post type (clubs) and get:

website.com/clubs/germany website.com/clubs/germany/brandenburg website.com/clubs/germany/brandenburg/potsdam

And each URL will show a list of clubs with that specific (child) taxonomy selected. And this is what I can't quite figure out, if this is possible with the plugin data, wp_query and rewrites?

I realise this is outside the scope of the plugin, so no worries if you can't advice.

Beee4life commented 2 years ago

I'm not sure if it can be automated It can, just by using custom queries, because if you have location data stored, it's available as meta data and therefor theoretically queryable.

Beee4life commented 2 years ago

On a side note, I am considering storing, city/country and state as individual meta values, which would make it a lot easier for you to query I think.

karlsan commented 1 year ago

Hi and I hope you've had a good year! Thanks again for the work on this plugin. The project I was planning on using it on hibernated, but I'm starting to work on it again. I had a look at the plugin changelog, I take it that the meta values are still stored as an array, rather than individual values?

I still haven't figured out how to build the rewrites for a hierarchical custom fields archive setup, but think I might have to give up and get a better developer than me to build it for me :) Would just be curious to know if meta fields are staying as an array.

Beee4life commented 1 year ago

I take it that the meta values are still stored as an array, rather than individual values?

You are correct sir, but I do plan to look into it on short notice.

I still haven't figured out how to build the rewrites for a hierarchical custom fields archive setup

What is not working ? Creating the URL or querying the posts on that specific page ?