Support » Themes and Templates » track sql query

  • I opened the query function in wp-config.php ::
    define('SAVEQUERIES', true);
    Then I got the sql on my custom page : searchpage.php , (use WP_Query($args))
    ……

    [26] => Array
            (
                [0] => SELECT SQL_CALC_FOUND_ROWS  xhna_posts.ID FROM xhna_posts  INNER JOIN xhna_postmeta ON (xhna_posts.ID = xhna_postmeta.post_id) WHERE 1=1  AND xhna_posts.post_type = 'post' AND ((xhna_posts.post_status = 'publish')) AND ( (xhna_postmeta.meta_key = '_description_value' AND CAST(xhna_postmeta.meta_value AS CHAR) LIKE '%华盛顿%') ) GROUP BY xhna_posts.ID ORDER BY xhna_posts.post_date DESC LIMIT 0, 12
                [1] => 0.0033919811248779
                [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sahifa/searchpage.php'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts
            )
    
        [27] => Array
            (
                [0] => SELECT   xhna_posts.* FROM xhna_posts  WHERE 1=1  AND xhna_posts.ID IN (2953,2786,2770,3661,3045,3523) AND xhna_posts.post_type = 'post' AND ((xhna_posts.post_status = 'publish'))  ORDER BY xhna_posts.post_date DESC
                [1] => 0.00063514709472656
                [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sahifa/searchpage.php'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts, get_posts, WP_Query->query, WP_Query->get_posts
            )
    
        [28] => Array
            (
                [0] => SELECT t.*, tt.*, tr.object_id FROM xhna_terms AS t INNER JOIN xhna_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN xhna_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (3045, 3661, 3523) ORDER BY t.name ASC
                [1] => 0.00084185600280762
                [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sahifa/searchpage.php'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts, get_posts, WP_Query->query, WP_Query->get_posts, update_post_caches, update_object_term_cache, wp_get_object_terms
            )
    
        [29] => Array
            (
                [0] => SELECT post_id, meta_key, meta_value FROM xhna_postmeta WHERE post_id IN (3045,3661,3523) ORDER BY meta_id ASC
                [1] => 0.00050997734069824
                [2] => require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/sahifa/searchpage.php'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts, get_posts, WP_Query->query, WP_Query->get_posts, update_post_caches, update_postmeta_cache, update_meta_cache
            )
    ......

    I am sure array[26] got nothing fome db, but the following array[27]\[28] got 3 posts.
    So my question is where these sql come from?

Viewing 3 replies - 1 through 3 (of 3 total)
  • my searchpage.php:

    <?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$district = $_GET['district']; //get the district from form
    		$args = array(
    			'post_status' => 'publish',
    			'paged' => $paged ,
    			'posts_per_page' => '12',
    			'relation' => 'AND',
    			'meta_query' => array(
    				array(
    					'key' => '_description_value',
    					'value' => $district,
    					'compare' => 'LIKE'
    				)
    			)
    		 );
    		$query = new WP_Query( $args );	?>
    	<?php if ( !($query->have_posts()) ) : ?>
                 --------do nothing-------
    	<?php else : ?>
    	<?php while ( $query->have_posts() ) : $query->the_post(); ?>
              --------loop-------
    	<?php endwhile;?>
    	<?php wp_reset_postdata();?>
    <?php endif; ?>

    I think the $query is null, it should do nothing. But it got 6 IDs in array[27], that confused me a lot.

    Who can tell me where are the 6 IDs came from?

    Is there any invisible sql query belongs to WP theme?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘track sql query’ is closed to new replies.