I have filter plugin on page. And I get generated SQL query by shortcode presets and query string params.
So I want to get SQL query without affecting by query string GET params.
For example. I have page url where I have a filter.
1 example
https : //example.com/snapbacks/
So if I have url like this. WP_Query generates this SQL query
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (38) AND wp_posts.ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (341)
)
) AND wp_posts.post_type = 'product' AND ((wp_posts.post_status =
'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 16
2 example
If I have url page like this
https : //example.com/snapbacks/?pa_brand=nike
I have this sql query
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (46) AND tt1.term_taxonomy_id IN (38) AND wp_posts.ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (341)
)) AND wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 16
So I have a several questions.
- How to get sql query showed in first example on page https : //example.com/snapbacks/?pa_brand=nike where "?pa_brand=nike" part added.
- How WP_Query generates SQL query? From url or $_GET/$_REQUEST arrays?