if (!$temp[0] == 'date') { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = $temp[0]; } if (stristr($product_sort, 'price')) { if (empty($product_price_range)) { add_filter('posts_join', 'compare_join_price_range'); add_filter('posts_groupby', 'compare_groupby_price_range', 10, 2); } add_filter('posts_fields', 'compare_filter_posts_fields', 10, 1); add_filter('posts_orderby', 'compare_orderby_price'); } } $products = new WP_Query($args); $product_ids = wp_list_pluck($products->posts, 'ID'); $product_metas = compare_product_item_meta($product_ids); $page_links_total = $products->max_num_pages; $pagination_args = array('prev_next' => true, 'end_size' => 2, 'mid_size' => 2, 'total' => $page_links_total, 'current' => $cur_page, 'prev_next' => true, 'prev_text' => __('Prev', 'compare'), 'next_text' => __('Next', 'compare'), 'type' => 'array'); $page_links = paginate_links($pagination_args); $pagination = compare_format_pagination($page_links); $counter = 0; ?> <form action="<?php echo esc_url(compare_get_permalink_by_tpl('page-tpl_search')); ?> " class="search-filter"> <section> <div class="container"> <div class="row"> <div class="col-md-3"> <div class="search-overlay sidebar">
function compare_generate_products_panel($source, $rows, $products) { $list = ''; $args = array('post_type' => 'product', 'posts_per_page' => $products, 'post_status' => 'publish'); switch ($source) { case 'popular': $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'product_clicks'; $args['order'] = 'DESC'; break; case 'seller': $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'product_store_clicks'; $args['order'] = 'DESC'; break; case 'ratings': $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'average_review'; $args['order'] = 'DESC'; break; } $products = new WP_Query($args); $product_ids = wp_list_pluck($products->posts, 'ID'); $product_metas = compare_product_item_meta($product_ids); $html_container = array(); if ($products->have_posts()) { $columns = ceil($products->post_count / $rows); $counter = 0; while ($products->have_posts()) { $products->the_post(); if ($counter == $columns) { $counter = 0; } $counter++; if (empty($html_container['column' . $counter])) { $html_container['column' . $counter] = ''; } ob_start(); include get_template_directory() . '/includes/product-box.php'; $html_container['column' . $counter] .= ob_get_contents(); ob_end_clean(); } $list .= '</div>'; } wp_reset_postdata(); for ($i = 1; $i <= $columns; $i++) { $html_container['column' . $i] = '<div>' . $html_container['column' . $i] . '</div>'; } return join('', $html_container); }
public function widget($args, $instance) { extract($args); $title = empty($instance['title']) ? '' : $instance['title']; $items = empty($instance['items']) ? '' : $instance['items']; echo $before_widget . $before_title . $title . $after_title; $latest = new WP_Query(array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $items)); $product_ids = wp_list_pluck($latest->posts, 'ID'); $product_metas = compare_product_item_meta($product_ids); if ($latest->have_posts()) { while ($latest->have_posts()) { $latest->the_post(); include get_template_directory() . '/includes/product-box.php'; } } wp_reset_postdata(); echo $after_widget; }