[wp-hackers] Compare "products"

Rilwis rilwis at gmail.com
Wed Jun 8 14:05:06 UTC 2011


- I think you don't need to use foreach loop
on $wp_query->query_vars['productIDs'], because the 'post__in' parameter
accept an array for its value.

- And to be sure that the parameter is safe, you should sanitize it. Here's
my sample code:

$products_to_compare = get_query_var('productIDs');
$products_to_compare = array_map('intval', $products_to_compare);

$products_query = new WP_Query(array('post__in' => $products_to_compare));

5. A new custom page template receives the vars through they query string
> and creates a custom query like that:
>
> *$products_to_compare = array();*
> *foreach ($wp_query->query_vars['productIDs'] as $product) {*
> * **$products_to_compare[] = $product;*
> *}*
> * $products_query = new WP_Query(array('post__in' =>
> ($products_to_compare)));*
>
> Everything seems to be working just fine, but i have a couple of questions:
>
> 1. *$products_to_compare[] = $product;* Do i need to sanitize anything
> around here? I mean i pull values from the URL.
> 2. Let's say that my products are displayed with pagination (e.g. 10
> products per page). How could i keep the values of the checkboxes from
> multiple pages? Cookies? Something else?
>

-- 
Rilwis
deluxeblogtips.com <http://www.deluxeblogtips.com>


More information about the wp-hackers mailing list