Home New Guten Forums WoodMart support forum limit search results to every single category

limit search results to every single category

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #510015

    web.mydecor
    Participant

    Hi,
    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,
    Ivana

    #510287

    Luke Nielsen
    Keymaster

    Hello,

    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 the woodmart_search_form function to the child theme and make changes there.

    Kind Regards

    #510343

    web.mydecor
    Participant

    Hi,
    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,

    #510446

    Luke Nielsen
    Keymaster

    Hello,

    Here is a screenshot: https://prnt.sc/_04l2uwYrpb0

    Let me know if you have any questions.

    Kind Regards

    #510861

    web.mydecor
    Participant

    Hi Luke,
    thank you very much for clarification. I have checked the code in inc/modules/search.phpfrom 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.phpfrom 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,

    #510877

    Luke Nielsen
    Keymaster

    Hello,

    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

    #510894

    web.mydecor
    Participant

    Hi 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.
    #511333

    Luke Nielsen
    Keymaster

    Hello,

    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

    #511589

    web.mydecor
    Participant

    Hello 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.
    #512013

    Luke Nielsen
    Keymaster

    Hello,

    You need to replace name="cat"with name="product_cat" in the input you added. So then it would work.

    Kind Regards

    #512069

    web.mydecor
    Participant

    Thank 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,

    #512355

    Luke Nielsen
    Keymaster

    Hello,

    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

    #512361

    web.mydecor
    Participant

    Ok, thank you very much for the information! 🙂

    Have a great day!
    Kind regards,
    I.

    #512486

    Luke Nielsen
    Keymaster

    Hello,

    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

Viewing 14 posts - 1 through 14 (of 14 total)

The topic ‘limit search results to every single category’ is closed to new replies.