[wp-hackers] Compare "products"

Gerasimos Tsiamalos tsiger at gmail.com
Wed Jun 8 10:28:53 UTC 2011


Hello People,

I'm writing a small "product" comparison system in WordPress and i'd like
your thoughts on this.
Here's what i've done so far.

1. Created a custom post type called "Products"
2. A custom page template where i list my products with a simple loop
wrapped in a <form> with a method=GET
3. In every product i have a checkbox field with a name of productIDs[] and
as a value i pass the the_ID();
4. In my functions.php i let WordPress know that i have a new query_var like
that:

*add_filter('query_vars', 'product_var' );*
*function product_var( $pvar )*
*{*
* **$pvar[] = 'productIDs';*
* **return $pvar;*
*}*

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?

-- 
Best Regards
*Gerasimos Tsiamalos*
Web Developer
8 A.Papandreou str, Thessaloniki, 57010
t: +30 2310 358548
twitter: @tsiger <http://www.twitter.com/tsiger>


More information about the wp-hackers mailing list