Home New Guten › Forums › WoodMart support forum › limit search results to every single category
limit search results to every single category
- This topic has 13 replies, 2 voices, and was last updated 1 year, 9 months ago by
Luke Nielsen.
-
AuthorPosts
-
November 5, 2023 at 9:10 pm #510015
web.mydecorParticipantHi,
I use Relevanssi along with your theme.
I would like to have funcionality – if user is inside product category page and perform the search than he will see only products that is belongs to the current category.The plugin author gives this idea:
You need to modify the search form so that it adds the current category as a parameter to the search form.
<input type=”hidden” name=”cat” value=”X” >
where X is the current category ID number. How that is done depends so much on your theme that I can’t comment much on that.
Can you please advise of how to edit and implement the code inside the woodmart theme?
I have created this code, but not sure:<input type="hidden" name="cat" value="<?php echo get_queried_object_id(); ?>">
Thank you very much.
Best regards,
IvanaNovember 6, 2023 at 5:49 pm #510287
Luke NielsenKeymasterHello,
In the
inc/modules/search.php
file on the 234 line you can see the form and in that form you can add your custom code. But in first you need to copy thewoodmart_search_form
function to the child theme and make changes there.Kind Regards
November 6, 2023 at 9:06 pm #510343
web.mydecorParticipantHi,
thank you.
On the line 234 of search.php, I have found only this code:
'search_again' => $search_again,
suppose it is not correct.
Could you please share more closer information? Would be very appreciated.Best regards,
November 7, 2023 at 10:52 am #510446
Luke NielsenKeymasterHello,
Here is a screenshot: https://prnt.sc/_04l2uwYrpb0
Let me know if you have any questions.
Kind Regards
November 8, 2023 at 3:46 pm #510861
web.mydecorParticipantHi Luke,
thank you very much for clarification. I have checked the code ininc/modules/search.php
from line 234 and added this piece of code into it<input type="hidden" name="cat" value="<?php echo get_queried_object_id(); ?>" />
– as Relevanssi author confirmed.I am struggling with the second part as you suggested
But in first you need to copy the
woodmart_search_form function
to the child theme and make changes there.Should I copy the whole code from already edited
inc/modules/search.php
from line 64 till the end of 809 line and copy it into child functions.php?
I apologize if this is maybe out of scope of support since I am the beginner with coding.Any advice I would highly appreciate.
Kind regards,
November 8, 2023 at 4:24 pm #510877
Luke NielsenKeymasterHello,
You need to copy (into child functions.php) only the function related to the “search form” in which you have added an additional line of code.
Video: https://take.ms/aydkg
You can also reach out to us if you have any questions.
Kind Regards
November 8, 2023 at 5:00 pm #510894
web.mydecorParticipantHi Luke,
thank you a lot for being so helpful 🙂I followed your guides, still it looks its not working, as on the product category page of Kitchen appliances I can filter through furniture products. Ive tried deactivate plugins, clear cache but no luck.
If you maybe have some hint, will be glad, if not, I guess I let it be for now as this customization might be over the official scope of support.
Kind regards,
Attachments:
You must be logged in to view attached files.November 10, 2023 at 10:12 am #511333
Luke NielsenKeymasterHello,
Sorry, I cannot tell you exactly but most likely, the issue is in the custom code itself.
Of course, if you’re having trouble of any kind issue, please let me know. I’ll do everything I can to help.
Kind Regards
November 10, 2023 at 8:24 pm #511589
web.mydecorParticipantHello Luke,
yes, I have checked and it seems that the code is correct as it can read the product category ID, but still it returns the search from every category. May it be that the bug is somewhere in the theme code?
Kind regards,
Attachments:
You must be logged in to view attached files.November 13, 2023 at 4:21 pm #512013
Luke NielsenKeymasterHello,
You need to replace
name="cat"
withname="product_cat"
in the input you added. So then it would work.Kind Regards
November 13, 2023 at 6:49 pm #512069
web.mydecorParticipantThank you, Luke, now that works perfectly!
Might have only one more question.
Is it possible to have one search bar in the sidebar of category page that would filter current product category only, and one search bar in the header of the page that would search through all of the products on the site?
Because now both of them search in category, when I am in category page.Kind regards,
November 14, 2023 at 6:39 pm #512355
Luke NielsenKeymasterHello,
Maybe, but your problem appeared because you added this input without any conditions for all searches. So you need to create some conditions so that input will appear in the needed search. (you can also use the variable
$show_categories
) and then everything will do as you need)Kind Regards
November 14, 2023 at 6:48 pm #512361
web.mydecorParticipantOk, thank you very much for the information! 🙂
Have a great day!
Kind regards,
I.November 15, 2023 at 10:21 am #512486
Luke NielsenKeymasterHello,
You are welcome! In case you need any additional help, I’d be more than happy to assist you.
Have a good day!
Kind Regards
-
AuthorPosts
The topic ‘limit search results to every single category’ is closed to new replies.
- You must be logged in to create new topics. Login / Register