在$ args =中使用imploded数组

时间:2015-03-11 21:39:16

标签: php arrays implode

将内爆数组插入$ args语句的正确方法是什么? $ products = array(IMPLODED ARRAY HERE !!); ......我希望到目前为止我做的事情是正确的。我编辑了这个以包含整个页面。

<?php
/*
* Template Name: stats
*/
get_header();
?>

<div class="row">
<div class=large-12 columns">


<?php


$order_items = apply_filters(  'woocommerce_reports_top_earners_order_items', $wpdb->get_results( "

SELECT order_item_meta_2.meta_value as product_id, SUM(  order_item_meta.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items

LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id

LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id

LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID

WHERE posts.post_type = 'shop_order'

AND posts.post_status IN ( '" . implode( "', '", array( 'wc-completed',  'wc-processing', 'wc-on-hold' ) ) . "' )

AND order_items.order_item_type = 'line_item'

AND order_item_meta.meta_key = '_line_total'

AND order_item_meta_2.meta_key = '_product_id'


GROUP BY order_item_meta_2.meta_value

" ));

?>

<?php
$current_user = wp_get_current_user();
$cat = $current_user->piwik;

$args = array( 'post_type' => 'product', 'posts_per_page' => -1,    'product_cat' => $cat);
$loop = new WP_Query( $args );



$temp = array();
while ( $loop->have_posts() ) : $loop->the_post();
$temp[] = get_the_ID() ;
endwhile;



$comma = implode(" , ", $temp);


 wp_reset_query(); 

 ?>


 <?php

 $totalsales = 0;

 $products = $comma;
 //Gather Totals
 foreach ($order_items as $item) {

 if (in_array($item->product_id, $products)) {

    $totalsales = $item->line_total + $totalsales;

    $title = $item->product_id;
 }


 }

 ?>


<div class="large-4 columns">
<table>
<tr>
<td><?php echo get_the_title ($title) ;?></td>
<td><?php echo $totalsales ;?></td>
</tr>
</table>

</div>

</div>
</div>
<?php get_footer();?>

0 个答案:

没有答案