• Goal is to display a list of recent posts visited. (including thumbnails) I’ve set a cookie saving the post id’s of recent posts and if i echo $_COOKIE[‘pages_visited’]; i get a successful result of ’60, 54, 33, etc’.

    My question id how do I get this to work in a query, the code i have is:

    <?php $post_list = $_COOKIE['pages_visited']; ?>
    
    <?php query_posts('post_id=array('.$post_list.')&showposts=4&post_type=post_therapists'); ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <p><?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title(); ?>
    </a></p>
    
    <?php  endwhile; ?>

    Any ideas anyone?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter formica

    (@formica)

    Doh! Structured wrong. Codex

    <?php $post_list = $_COOKIE['pages_visited']; ?>
    <?php  wp_reset_query();  // Restore global post data stomped by the_post(). ?>
    <?php query_posts( array('post__in' => array($post_list), 'orderby' => 'post__in', 'post_type' => 'post_therapists') ); ?>
     <?php while ( have_posts() ) : the_post(); ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    Thread Starter formica

    (@formica)

    Sorry was too hasty. For some reason the above won’t work without exploding the string see here

    Correct code for putting a dynamic string in a query:

    <?php $post_list = $_COOKIE['pages_visited']; ?>
    
    <?php query_posts( array('post__in' => explode(',', $post_list), 'post_type' => 'post_therapists') ); ?>
    
    <?php while ( have_posts() ) : the_post(); ?>

    Thanks ixwa for posting.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using cookies in query’ is closed to new replies.