The WordPress Search explained

To understand how WPSOLR can integrate Apache Solr and the WordPress search, let’s first dive a little bit in the hidden world of WordPress core features. If you spend a few moments understanding the following documentation, you will be much more well armed to setup WPSOLR. So, let’s go !
Here are the (simplified) standard WordPress search workflow steps, also represented in the cinematic above:
- A page is loaded, for instance by a user clicking on a link on your website.
- The WordPress core extracts the page url, with all it’s parameters. For instance: /?s=red+shoes&post_type=product for a WooCommerce search.
- The url parameters are used to build a WP_Query object, a high level WordPress api to build SQL queries.
- WordPress produces a SQL statement out of the WP_Query, and calls the database with the right SQL dialect (MySQL, PostgreSQL, …). This SQL is often complex, and merges results from several SQL tables (like products and attributes to retrieve the colour and sizes of shoes).
- The WordPress database executes the SQL statement, and returns results, which are stored in the WP_Query object. Notice that sometimes only the results Ids are returned, which will lead to more SQL executed to get other results details.
- WordPress will now load a php file, named a template. The template is stored on the current active theme directory. Which template is loaded depends on the standard template hierarchy (a way to link urls and template file names), or on the theme’s or plugin’s filters/actions. Notice that there are all sorts of search templates, from search.php, to categories lists, tags lists, and many others.
- The template will now loop on the results of the global WP_Query object (the Loop), and use whatever it needs to present them (css, javascript, html, ….).