Issue with Tag URL Generation Leading to 404 Error
-
Hi there! I encountered an issue with the Search & Filter Free plugin where searching by tags resulted in a 404 error when using a custom permalink structure. The search worked fine for categories but not for tags.
Steps to Reproduce:
- Set up the Search & Filter Free plugin with a form to search by name, category, and tag.
- Use a custom permalink structure.
- Submit a search using only tags.
Expected Behavior:
The search should return results without resulting in a 404 error.
Actual Behavior:
Submitting a search with tags resulted in a 404 error page.
Solution:
To resolve the issue, I modified the URL generation in the plugin’s code:
- I added the following line to correctly get the tag base:
$tag_base = ( get_option( 'tag_base' ) === '' ) ? 'tag' : get_option( 'tag_base' );
- I updated the URL path to include the tag base correctly:
$tag_path = $tag_base . '/' . $tags . '/';
instead of$tag_path = 'tag/' . $tags . '/';
This change ensured that the tag URLs were generated correctly, eliminating the 404 error when searching by tags.
My Question:
I would like to know if there are any existing filters or actions in the plugin that could be used to make this change update-proof, since direct changes to the plugin files can be overwritten with future updates. I couldn’t find anything about it in the documentation.
Thank you!
- You must be logged in to reply to this topic.