I'm trying to retrieve data set in a cookie and use this to run a query.
I've set the cookie in functions.php like so;
add_action( 'init', 'resultsCookie' );
function resultsCookie() {
setcookie( 'your-results', '18,17,11,8,10,27,26', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
}
While I can echo the string, I can't seem to get this functioning within the query;
$cookie_array = $_COOKIE["your-results"];
// Test output
echo $cookie_array;
$sug_args = array(
'post_type' => 'product',
'post__in' => array( $cookie_array )
);
$sug_query = new WP_query ($sug_args);
if($sug_query->have_posts()) : while($sug_query->have_posts()) : $sug_query->the_post();
// Run Loop
wc_get_template_part( 'content', 'product' );
endwhile; endif; wp_reset_query();
Any ideas?
$_COOKIE["your-results"]
? If this is an array, you don't need to wrap this withinarray( $cookie_array )
. Try(array) $cookie_array;
instead.