Hi there,
Waqar helped me find an answer to this in this thread,
https://toolset.com/forums/topic/how-to-properly-create-a-page-for-a-top-level-taxonomy/
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;
}
else
{
// 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!
G