• andreistaicu

    (@andreistaicu)


    Hi,

    I’m building a site for a public library and many users are using the site search expecting to get results from the public catalog (opac). So they are searching for author names and book titles and, of course, getting no results. So I’m trying to extend the WP search functionality to also search the catalog.
    I already got the PHP code to do this (it’s just some SOAP calls), but I’m stumped on how to integrate with WP (not much experience with WP code, but I’m willing to learn).
    So my problem is twofold:
    – how to extend the default search function to also return my custom data (and what should be the format of the returned data); it will be just a list of links.
    – how to split the search results page in two, displaying the default results on one side and my custom results on the other (this is a lower priority)
    I’ve been reading up on custom searches, but almost all of them focus on creating search forms, using custom taxonomies and creating custom search results page templates.
    Any help would be appreciated, including RTFMs (pointing to the relevant FMs).

    Also the code will end up on github (GPLed). Will post the link if anybody requests it (don’t want to pre-advertise).

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Since these are truly two separate searches, even the results are separated, I don’t see a need to get too involved with integrating with the default WP search. You basically only need to determine the search terms and display the opac results on the same results page. The search terms for the default WP search are available from $_GET['s'] or get_search_query().

    Display the opac results by customizing the search results template of your theme, usually search.php. Don’t directly edit theme files though. Create a child theme, copy the parent’s template file over to the child and edit the child’s copy.

    You can put the opac search code right on the template, or put it in the child’s functions.php as a function that’s called from the template. If you’re getting a list of links as results, you may be able to simply echo out the entire list. If you need to modify the list in order to customize the output, you could use string functions to add content, or consider exploding the list somehow into an array. Modifying array elements is likely easier than using string functions on the entire list. Then loop through the array elements to generate output just as the standard WP Loop does for WP results.

    Thread Starter andreistaicu

    (@andreistaicu)

    Hi bcworkz,

    Thanks for your advice, it worked. It looks like I was overcomplicating things.
    If anybody is interested, the code is here:
    https://github.com/smarmie/aleph-wordpress-search
    I still have a ways to go, but it’s an initial working version.
    I hope posting this link is not against forum rules.

    Thanks again.

    Moderator bcworkz

    (@bcworkz)

    ?? I think I initially overcomplicate every coding project I’ve ever done. Then once it’s done, I often find myself realizing “Oh, that wasn’t too bad at all!”

    Links to related code are always welcome here. Only off topic promotional links are prohibited. That would be spam. If you post a lot of links your post could get flagged as spam, but if the links are on topic, one of the mods will soon release it from the spam queue.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom results from external sources’ is closed to new replies.