WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Relevanssi] Limit search to certain pages / subpages ? (13 posts)

  1. maorb
    Member
    Posted 5 years ago #

    Well, since it's another issue, I've created a new thread.

    Is it possible to limit the search for certain pages/subpages?

    I have a site I built to a customer, and this site holds, among the regular article and pages, a lot of static pages with a specific template that show data of companies they work with. All of these data is inserted in custom fields and displayed through that page template.
    These companies pages are divided to some sections (parent/child/grand).

    Now, the client wants to have, except for the regular site search that is in the top navbar, another search box that will appear in the side bar, that will search only for companies, which means - limiting the search to a page and all of it children/grandchildren using customfields indexing.
    Is that possible with Relevanssi, and if not, do you know such a plugin that supports that?

    Thanks again
    Maor

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Posted 5 years ago #

    You're really pushing the limits of what WordPress can do...

    Relevanssi is plugged to the basic WordPress search and that places some limitations. The most important is the limit of parameters that can be passed to the plugin: WordPress prevents passing anything custom.

    However, you can limit search to certain entries using categories or tags. You can pass the cat variable to the search using hidden input field like

    <input type='hidden' name='cat' value='list of cats and tags' />

    So, if you tag the pages with a specific tag and then insert a second search form with the hidden variable. IvyCat is using a similar system, they have a main search that searches everything and knowledge base search that only searches the knowledge base.

    So yes, I suppose it can be done. You won't get pretty excerpts for the results, as the data is in custom fields and not in the entry contents, but other than that, it should work.

  3. maorb
    Member
    Posted 5 years ago #

    Thanks msaari for your detailed reply.

    Well, I agree it's kinda pushing the limits... If all the requirement and ideas this clients comes up with every morning have been told at the start, I might have told him to choose another platform, but now he doesn't want to build everything from the begining....

    Anyway, for you solution - how can I have tags for my static pages? and is there a way assign a special permanent tag automatically for pages in a certain page template? (since if one adds another company and forget to add the tag, it won't be searched...)

    The problem will be, as you mentioned, with the excerpts for the results. Is there a way to display for example only the page name, so to prevent the non-pretty excerpts that has no data inside?

  4. Mikko Saari
    Member
    Posted 5 years ago #

    Ah, you're right, pages don't have tags or categories. Then I'm afraid it's impossible, because that's the only parameter WordPress allows the search form to pass.

    Well, not impossible, but it requires some hacking. You could use a non-existing category ID and have that map to something else, like pages with certain custom field (I assume there's a custom field that appears on every page you want included in this special search). I'll think about this a bit, I can probably provide you with the necessary code.

    What comes to results, that's just a question of templates and outside the scope of Relevanssi... I'm not sure if you can do two different search templates or use conditionals somehow. Well, if the excerpts come up empty, you can probably do some PHP code that'll prevent displaying excerpts if they're empty.

  5. Mikko Saari
    Member
    Posted 5 years ago #

    Ok, I've got a fix for you. Check out this file. To use it, you need

    1) a search form with hidden form input field that's called "cat" and has a value of "custom"
    2) change the variable on line 438 to contain the name of a custom field that appears in all pages you want to include in this search

    See how that works. If it does and you're making money out of this, please consider a donation. PayPal link can be found on Relevanssi home page.

  6. maorb
    Member
    Posted 4 years ago #

    You could use a non-existing category ID and have that map to something else, like pages with certain custom field (I assume there's a custom field that appears on every page you want included in this special search). I'll think about this a bit, I can probably provide you with the necessary code.

    I'm not sure I understand what you've meant by map a non-existing category ID to map to somehing else. How this could be done and helpful?

  7. maorb
    Member
    Posted 4 years ago #

    Ok, I've got a fix for you. Check out this file. To use it, you need

    Msaari, thanks a lot for your help. I'll try that soon and will reply to tell you if it worked!

  8. maorb
    Member
    Posted 4 years ago #

    I've tried to download your file, but it's size is 0kb and the zip is empty..
    May you upload it here again? or just email me the file to
    maor (AT) maorb.info

    Thanks a lot for your former help, I managed to limit a search to certain category, now I just need the fix you made to try and check the issue with limiting to those certain pages with custom fields.

    Maor

  9. Mikko Saari
    Member
    Posted 4 years ago #

    Ok, I've sent you the file in email.

  10. riaanvj
    Member
    Posted 4 years ago #

    Hi msaari

    Would it be possible if you can send me that fix (zip file) also please?
    riaan121 (AT) gmail.com
    Thanx

  11. eagerness
    Member
    Posted 4 years ago #

    This is also the exact thing I'm looking for! :) Is it possible for another copy to post (at) terjeandersen (dot) net ?

  12. Mikko Saari
    Member
    Posted 4 years ago #

    It's not a simple fix, but requires some PHP knowledge. I don't have time to do the fix for anybody else, but if you're a capable PHP coder, let me know and you can have the file if you promise not to ask me any questions about it =)

  13. eagerness
    Member
    Posted 4 years ago #

    Hah :) That's OK, chuck it over ;)

Topic Closed

This topic has been closed to new replies.

About this Topic