Skip Navigation

[Resolved] State & City with same name, City archive page displaying State template instead

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 10 months, 2 weeks ago.

Assigned support staff: Waqar.


Hi there,

Waqar helped me find an answer to this in this thread,

This works great, but I just noticed a glitch on my site.

The code Waqar helped me with in the support thread mentioned above there sets the correct Toolset Archive Template to show for either a state or city level archive term.

This works great, but there is ONE situation where the city is the same name as the state, New York.

The URL looks like .com/laundromats/new-york/new-york

When I put that in as the URL, it should take me to the city archive page like it does with every other city in New York, ex. /laundromats/new-york/harrison, but when it's /new-york/new-york, it takes me instead to the STATE archive page...

Is there some way we can just insert a single line of code into the solution that Waqar provided to take care of this exception case?

Like into the following code somewhere:
add_filter( 'wpv_filter_force_wordpress_archive', 'wpv_filter_force_wordpress_archive_tax_1', 30, 2 );
function wpv_filter_force_wordpress_archive_tax_1( $wpa_assigned, $wpa_loop ) {

// slug of the target taxonomy
$target_tax_1_slug = 'laundromats-near-me';
// ID of the WP Archive created for the state level terms
$target_tax_1_state_archive_id = '41';
// ID of the WP Archive created for the city level terms
$target_tax_1_city_archive_id = '46';

// check if the archive is for the target taxonomy term
if ( $wpa_loop == 'view_taxonomy_loop_'.$target_tax_1_slug ) {
// get information about the term whose archive page is being viewed
$term = get_queried_object();
// check if the current term has some parent
if($term->parent > 0) {
// if parent term exists it means it is a city term and assign the archive for the city
$wpa_assigned = $target_tax_city_archive_id;
// if no parent term exists it means it is a state term and assign the archive for the state
$wpa_assigned = $target_tax_state_archive_id;

return $wpa_assigned;

Thanks for all the help!



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)


Thank you for contacting us and I'd be happy to assist.

That custom code checks for the existence of a parent term for the dynamic assignment of the archives, so in theory it shouldn't be affected if the city and the state level terms have the same name.

Can you please share temporary admin login details of the website, where this behavior can be seen? I'll be able to review the setup and will try to reproduce this on a test website.

Note: Your next reply will be private and though no changes will be made on your website, it is recommended to make a complete backup copy, before sharing the access details.



Hey Waqar,

I looked at this a bit closer and realized my mistake.

So it looks like when the city level archive slug was created, instead of just being "new-york", it created it as "new-york-new-york".

So for example, the city level archive page URL is , laundromats/new-york/new-york-new-york

Is it necessary to have it like this, or could I change it to /new-york/new-york without creating problems?

Thanks again for the insights 🙂




Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

Yes, in my tests, I noticed the same behavior for the child-level term slugs, and WordPress seems to ensure unique slugs this way.
( you'll see the same behavior for the same parent-child term slugs handling even with all plugins are disabled )

A workaround, in this case, would be to add "state" and "city" in the slugs, where the state and city names are the same:

- new-york-state
- new-york-city