The WordPress Search explained
To understand how WPSOLR can integrate search engines, 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:
- The visitor of the WordPress website enters “red shoes” in any of the search bars.
- The client sends a query to the WordPress server. The url contains the following parameter : /?=red+shoes. If you have selected filters, it could look like : /?s=red+shoes&post_type=post.
- The WordPress core extracts the page url, with all it’s parameters.
- 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, ….).