I've collected an array and set-up a cookie via functions.php, both work fine. However, I really need to post the data to the function and set the cookie as this information will vary per customer.

The array is of product IDs collected after WP_Query.

$ids = array();

Here is my cookie code, I'd need to replace the 'ID_ARRAY' text with the actual array.

add_action( 'init', 'resultsCookie' );
function resultsCookie() {

   setcookie( 'your-results', 'ID_ARRAY', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );

1 Answer 1


You could try serializing the array so that it becomes a flattened textual representation of the values it contains. e.g.

$testArr = [3,4,"test", 56];
echo serialize($testArr);



However, you should probably consider using user sessions for this rather than cookies.

  • My thinking was that cookies would be preferable as the user would most likely not be signed in, and therefore it would be good if the data could be stored beyond the initial session. Not sure how serailising data posts to the function though, could you explain? Commented Jul 8, 2015 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.