• Hi,
    I’d like to replace the built-in search query with a custom query that takes advantage of fulltext indexing and sorts results by rank. I’ve written the SQL statement, but I’m not sure which action or filter to implement it in. And thus do I execute it with $wpdb->get_results() or am I supposed to pass it back to Word Press somehow?

    I’ve looked at the “request” filter and the “pre_get_posts” action, but the documentation is limited and these look more like places to manipulate query variables than an appropriate place to inject a SQL statement.

    Basically my concern is the same as this thread: “Alternative to query_posts for main loop?” where I don’t want my query running AFTER the default query has already executed.

    Thanks

    Edit: I should add that I’m trying to use the same index/loop to display the search results as I use when someone clicks on a tag or category. Except in the latter two cases, I’ve added a “posts_orderby” filter to sort by title ascending.

    The pseudocode would be:

    – if is_search() then execute custom SQL query, else execute default query (filtering WHERE clause to order by title)
    – then pass either set of results to central loop so the output formatting looks the same no matter if this is a search, category listing, or tag listing.

  • The topic ‘Bypass Default Search Query Behavior with Custom SQL Query’ is closed to new replies.