我有这个meta\u查询:
$today = current_time('Ymd');
$args = array (
'numberposts' => -1,
'post_status' => 'publish',
'post_type' => 'product',
'meta_query' => array(
'relation' => 'AND',
'start_clause' => array(
'key'=>'flash_sale_start',
'value' => $today,
'compare'=> '<=',
'type' => 'DATE'
),
'end_clause' => array(
'key' => 'flash_sale_end',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
)
)
);
return $args;
}
// The main shop and archives meta query
add_filter( 'woocommerce_product_query_meta_query', 'custom_product_query_meta_query', 10, 2 );
function custom_product_query_meta_query( $meta_query, $query ) {
if( ! is_admin() )
return custom_meta_query( $meta_query );
}
其中取决于以下不显示orderby位置的sql查询:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
INNER JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id )
LEFT JOIN wp_acf_google_map_search_geodata AS acf_gms_geo ON wp_posts.ID = acf_gms_geo.post_id WHERE 1=1 AND wp_posts.ID NOT IN (968) AND (
wp_posts.ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id IN (10)
)
) AND (
wp_postmeta.meta_key = âtotal_salesâ
AND
(
(
( mt1.meta_key = âflash_sale_startâ AND CAST(mt1.meta_value AS DATE) <= â20180125â )
AND
( mt2.meta_key = âflash_sale_endâ AND CAST(mt2.meta_value AS DATE) >= â20180125â )
)
)
) AND wp_posts.post_type = âproductâ AND (wp_posts.post_status = âpublishâ OR wp_posts.post_status = âcompleteâ OR wp_posts.post_status = âpaidâ OR wp_posts.post_status = âconfirmedâ OR wp_posts.post_status = âunpaidâ OR wp_posts.post_status = âpending-confirmationâ OR wp_posts.post_status = âcancelledâ OR wp_posts.post_status = âprivateâ)
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value+0 DESC, wp_posts.post_date DESC LIMIT 0, 100
我还有一个元查询:
$products = new WP_Query( array (
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $atts['limit'],
'meta_query' => array(
'relation' => 'AND',
'start_clause' => array(
'key' =>'flash_sale_start',
'value' => $today,
'compare' => '>',
'type' => 'DATE'
),
'end_clause' => array(
'key' => 'flash_sale_end',
'value' => $today,
'compare' => '>',
'type' => 'DATE'
),
'limit_clause' => array(
'key' => 'flash_sale_start',
'value' => $limitdate,
'compare' => '<=',
'type' => 'DATE'
)
)
));
}
ob_start();
if ( $products->have_posts() ) { ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php
} else {
do_action( "woocommerce_shortcode_products_loop_no_results", $atts );
echo "<p>Aucune vente à venir pour le moment.</p>";
}
woocommerce_reset_loop();
wp_reset_postdata();
return '<div class="woocommerce columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>';
}
add_shortcode( 'upcoming_sales', 'upcoming_sales' );
此sql\U查询显示插件触发的orderby位置,该查询依赖于此sql\U查询:
SELECT wp_posts.*
FROM wp_posts
INNER JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1
ON ( wp_posts.ID = mt1.post_id )
INNER JOIN wp_postmeta AS mt2
ON ( wp_posts.ID = mt2.post_id )
LEFT JOIN wp_acf_google_map_search_geodata AS acf_gms_geo
ON wp_posts.ID = acf_gms_geo.post_id
WHERE 1=1
AND (
( wp_postmeta.meta_key = âflash_sale_startâ
AND CAST(wp_postmeta.meta_value AS DATE) > â20180122â
)
AND ( mt1.meta_key = âflash_sale_endâ
AND CAST(mt1.meta_value AS DATE) > â20180122â
)
AND ( mt2.meta_key = âflash_sale_startâ
AND CAST(mt2.meta_value AS DATE) <= â20180127â
)
)
AND wp_posts.post_type = âproductâ
AND ((wp_posts.post_status = âpublishâ))
GROUP BY wp_posts.ID
ORDER BY (POW((acf_gms_geo.lng-6.640710899999931),2) + POW((acf_gms_geo.lat-43.26768079999999),2)) ASC
您知道为什么插件不能在第一个sql查询中执行orderby吗?