Hopefully my title will get across what I’m after.
Here’s the scoop:
There’s a spot on the homepage that lists the “Service Area” of the client. This is shown as lists of towns with headers showing which county each list belongs to.
I created a custom post type service-area so the client will eventually be able to add/remove service areas as needed in the future. Each post represents a “city” and in each post they select which county this city belongs to (this is the sa_county custom field).
I came up with this block of code to display a single “county service area”:
The problem here, is that I have the meta_key and meta_value hard-coded into this block of code. There are eight total counties right now. That means eight total service area lists. I know I’m not a great programmer, but I know enough to know that having eight nearly identical blocks of code is just plain stupid.
I apologize for the newbie question, but how can I automate and make this nice and DRY?
Okay, I realized I could simply everything by making a few small changes. Instead of making each ‘town’ into a post, I deleted them all and turned each ‘county’ into a post. Then I added a repeater field, so the user creates a list of towns in each county. Pretty simple fix!
That being said, I’m still curious if my original question is even possible and/or even recommended ever.
I believe your second setup is better than the first. With your first setup, you need to get all of the counties first. It depends on the field type of the counties. If it’s a text, you need to get them using wpdb class.
I hope this makes sense.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users