• I’m working on a website where I pulled information of programs from an external API. I have it displayed on the WordPress website. As it is, the search bar only pulls results from items inputting into WordPress and is not fetching any results from the external API. Is there a way to have WordPress items and the API items both be fetched when a user uses the search bar?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You’d be having code doing two separate searches no matter what. That much is feasible. But how you might merge the results in a meaningful manner could be difficult. WP search results end up as an array of post objects. The display of results relies upon these being WP_Post objects. I imagine the API results are in some other form besides post objects.

    I suppose you could append the results of one search to that of the other, then usort() the whole thing based on some common element such as date. The sort callback would need to know how to access disparate data elements and still be able to properly compare the two. The output of results template would also need to be able to handle disparate data in a consistent way.

    Now if you need to also paginate the results it gets very tricky. You’d probably want to cache all results in the user’s session.

Viewing 1 replies (of 1 total)

The topic ‘Search function scanning for items from WordPress and external API items’ is closed to new replies.