From Query Parameters to SQL in WordPress
When the query parameters have been established in the wordpress, it is either by separate the URL provided by the reader or by having them explicitly set in a customized loop function, then translates those parameters into SQL for a database query by the WP_Query object’s get_posts() method. you can exercise great control over the type of, selection, and ordering of content through the query parameters of the function, the Core files of WordPress also exposes the filters to allow you to change the generated SQL for even finer-grain control over content selection and grouping.
SQL query basic format is: SELECT fields FROM table WHERE conditions. What is “fields”? “Fields” are the columns of the database that you want fetch; so usually don’t need to modify or change this part of the query. Where the “conditions” use in the WHERE clause change the ordering, grouping, and number of posts returned. When you dump out the generated SQL query by examining the request field of the WP_Query object, in the WHERE portion of the SQL contains 1=1 as the first conditional. If no other content selection parameters there, then1=1 ensures that the generated SQL isn’t syntactically malformed in the absence of other WHERE clauses; MySQL knows enough to ignore the 1=1 in the SQL optimizer.
The “Table” is not only the “posts” table in the MySQL database it contains in it fields all the post data; you may also need to an SQL JOIN of two or more tables where you need to select posts based on hierarchical metadata. The WordPress makes it easy to put multiple tags on a post, or to put a post in more than one category, but relational databases aren’t expert at managing these classified or networked relationships. Let’s suppose, to select the posts tagged Web-Design-London, then an SQL JOIN is required to first find Web-Design-London in the metadata taxonomy, then build an intermediate, in-memory table of posts that have been tagged with Web-Design-London, and then select posts whose IDs appear both in the intermediate table and the main WordPress content table. Database call this a inner join of two or more tables; Both query complexity and memory consumption is accurate of the multiplicative description.In the SQL request generation or creation, so there are a number of filters that are raise to give plugin authors late-binding and very explicit control over the SQL that gets executed.