• Resolved wrimomatt

    (@wrimomatt)


    I’m building a rather large directory of groups that spans several states. The groups are a custom post type and I’m thinking a custom taxonomy for states as parents and cities to be their children. That way I can output the directory by state and break it out by city. I’m looking to remove the redundancy of having my client enter the city and state though when entering other details about these groups.

    right now I have custom meta boxes for:

    Group Name
    Building Name
    Street Address
    City, State ZIP
    phone
    email
    time, date of meetings
    description of meeting = content

    Is there a way to query for the city and automatically get the parent state? I tried it as a list of terms and it doesn’t work because it spits them out alphabetically. So sometimes the State is in the right place, sometimes it’s before the city.

    Thanks for any ideas!
    -M

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    In hierarchical taxonomies, every term’s parent ID is part of the term object. If all cities have a parent state term, the state term’s ID is stored with the city term’s object. In a sense, there is no reason to even specify a state, since it’s part of the city term’s data. When you get a permalink for child terms, the parent path is normally part of the permalink. If you output the permalink for Chicago, it’ll look something like example.com/location/illinois/chicago/.

    It’s important though that not only is the hierarchy correctly setup, but the correct city is selected. There is much potential for ambiguity. For example, I think there is a “Jackson” in about half of all the states. One needs to select the correct “Jackson” for the state to be correct. There is little in common between Jackson MS and Jackson CA!

    Some template tags will list child terms under and indented from their parent, and the ordering of the top level terms can be based on several options, though alphabetical makes the most sense as long as child terms are under their parent. When there are many children, it can be a small challenge to locate the top level term one is looking for since parents occur infrequently.

    A common approach with hierarchies is to only offer top level terms for initial selection. After the top level is determined, only children of the selected term are offered. This is repeated through several levels sometimes. A “drill down” approach. Of course, this does not remove the redundancy you seek, but it does remove any ambiguity from common city names.

    I don’t really have a good answer for you, but hopefully you have enough information now to decide for yourself.

    Thread Starter wrimomatt

    (@wrimomatt)

    I love that you ended “I don’t really have a good answer,” when you gave an extremely thorough answer. This was very helpful. The redundancy is minor I think, compared to the potential issues created by trying to eliminate them. I did think about multiple town names, but only to rule out using two taxonomies (one for state, one for city). It also occurred to me from your explanation, that the full address will have an abbreviation, but I’d want the taxonomy to have the full state spelled out because it’s likely better for SEO.

    Anyway, big thanks.

    • This reply was modified 7 years, 10 months ago by wrimomatt.
    Moderator bcworkz

    (@bcworkz)

    Hehe. While I thought I was only giving you background information and not answering your question, I inadvertently did answer your question! You could setup state terms so the abbreviation is the slug and the full name is the term name. Then you can pick and choose which version to match or output by which term property you use.

    You had an issue with the term list. As long as the data exists, through one way or another you can get the desired output, even if you have to code it yourself. That shouldn’t be necessary, there’s a number of listing functions, one of them should work as long as they are fed the correct arguments. I’m unable to suggest the correct function, but I’ve seen results like you are seeking. I’m just bad with names.

    Thread Starter wrimomatt

    (@wrimomatt)

    My parents terms are not showing up in the URL of the child terms. So if I go to the URL “/cityname” it’s not preceded by the “statename”. If I manually enter the statename in the URL it DOES show all the cities, but the individual cities lose the statename in their URL.

    I’ve got hierarchical as true what else might I be missing? Thanks for any help.

    Thread Starter wrimomatt

    (@wrimomatt)

    Nevermind, the rewrite needs an additional nudge, apparently. All is well

    'rewrite' => array( 'slug' => 'prettyname', 'hierarchical' => true ),

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘automatically include parent w/ child custom taxonomy’ is closed to new replies.