Customize search result page according to category?
-
NOTE: I can’t publish web pages as they’re in a non-public environment. Feel free to move it into “developing with WordPress” if it’s too technical.
Hello, I’m struggling with search block and search results page, in TwentyTwentyfour theme.
Personal need: blog is based on two sections, each one has its posts categorized as “real world” and “fake world”. No particular customization in types and taxonomies, “it’s just “real world” and “fake world” are two categories with their own customized templates – fakepost and realpost, associated to their own template parts (headers and footers, meta and sidebars).
For the search block I changed its behaviour manually by code view, in each header, as follows:
<!-- wp:search {"showLabel":false,"buttonPosition":"button-only","buttonUseIcon":true,"query":{"cat":"xxx"}} /-->
“xxx” stands for the numeric ID corresponding to the desired category, let’s say “10” for real, “11” for fake.
This way, when I search for a keyword, it returns [siteurl]/?s=[keyword]&cat=[number] – this is what I wanted it to do.
But the issue comes in the results page!
- template parts are the default ones (good just for “real world” section);
- the search block included in results page, is obviously not customized.
Is there a way to tell the search form’s “get” method, ‘if search comes from /real go to result-real, if it comes from /fake, point to fake-results’?”
I googled and found that for customizing search template you should create a searchform.php file but, besides not working (I uploaded it into /templates/ folder), I don’t find the right instructions to build the condition to influence the form submission. And I don’t feel like changing the /wp-includes/general-template.
Thanks in advance for possible help
- You must be logged in to reply to this topic.