NO BUG: Taxonomy Archive Template not working after term_link filter used to rewrite slug

Browser: Chrome/Brave
OS:Windows 10
URL: n/a

[Moved from How-to to Bugs]


I have a taxonomy that I have created an archive template for in Bricks.

Before rewriting the taxonomy slug the template works fine. After rewrite the template doesn’t load and instead I get the 404 page as its looking for a page and not the template (presumably).

I have used term_link as in an example from the wordpress docs, similar to this:

function wpdocs_change_course_category_link( $url, $term, $taxonomy ) {
	if ( 'course_category' !== $taxonomy ) {
		return $url;

	return str_replace( '/course-category/', '/', $url );
add_filter( 'term_link', 'wpdocs_change_course_category_link', 10, 3 );

The rewrite works fine and taxonomy slugs are now as I want them.

How do I get the Bricks archive template for the taxonomy to recognise the new slug format?

I have flushed permalinks/rewrite rules by saving permalink settings.

Thanks :slight_smile:

Hi Macky,
Thank you for your report, but as far as I see, it’s not a Bricks bug. Please take a look here, this should work:

Best regards,

1 Like

Thank you for that information, I’ll take a look and see if it fixes my issue

FYI the code that is in the linked article throws an error if used as instructed by the post author. It looks like it was published in 2016 or earlier so might not work correctly with current PHP versions.

The article is useful and I should be able to glean the information that I need to fix this issue on my website. But maybe find a better article for future reference :slight_smile:

So on further inspection and testing, the information on the page that you shared seems wildly inappropriate for this situation.

I set up the ‘request’ filter and output $query to a log file. I then loaded the taxonomy template by viewing a taxonomy and the $query object was simply:

$query: Array
    [fr-retreat-category] => day-retreats

So the code that is on the shared page…

if( $query['attachment'] ) :
		$include_children = true;
		$name = $query['attachment'];
		$include_children = false;
		$name = $query['name'];
	$term = get_term_by('slug', $name, $tax_name); 

…fails at several points. I can adapt the code to check that the array items are set but that then means that the variable $name is not set, which is referenced further down the function.

Can you give me some better insight in to how to make bricks recognise the new taxonomy slug that I set up using the ‘term_link’ filter, so that the taxonomy template loads instead of the 404 template? All I want is to change the taxonomy slug from fr-retreat-category/day-retreats/ to /day-retreats/ and have the taxonomy template that I have set up in Bricks to load for the new URL. The template works fine when tested without changing the slug with the ‘term_link’ filter.

TIA for you help!