I have the following code snippet in WordPress functions.php file:
add_action('init', function() {
add_rewrite_rule('^explore-destinations/?(.*)','index.php?tt_destination=$matches[1]', 'bottom');
});
It works great when my url is: https://example.com/explore-destinations/north-america/illinois/ or https://example.com/explore-destinations/north-america/illinois/chicago. I have a filter that sets the query_vars tt_destination properly and parses it as a query var then builds/returns the page accordingly. For instance the query var in the second page above is set to: north-america/united-states/illinois/chicago and I am able to use it to direct a proper page template and render the content.
What is confusing me, is the following url: https://example.com/explore-destinations/north-america/ returns blank. I’m looking for it to return the continent (e.g. north-america).
Can anyone provide advice on what I’m doing wrong? Thanks in advance.
I have tried various machinations of the regex string, without any success — e.g. explore-destinations/?(.*) or ^explore-destinations?(.*)
I’ve tried rebuilding the permalinks after making the code changes without success.