• Hi There.

    I am trying to run a query that shows 4 posts, from a certain category and that excludes specific posts.

    I cannot figure out how to combine the “post_not_in” array with any other parameters.

    Here is a slightly simplified version of my code, if someone could please help me correct it as I can only do basic php, then I’d appreciate it ??

    <?php $args = array(
    ‘cat’ => ’64’,
    ‘showposts’ => ‘4’,
    array(‘post__not_in’=>array(121,)),
    );
    query_posts( $args );?>

    Regards

    Itai

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am not sure if this would work, but try something like

    <?php
    query_posts('posts_per_page=4&cat=64&post__not_in=121');
    ?>

    I like doing it that way instead of an array, because it is simpler to me. Separate any variables with a ‘,’ like (121,123,155). I hope it works for you.

    eitai2001,

    Give this a shot:

    <?php query_posts(array('category__and'=>array(64),'showposts'=>4,'orderby'=>rand,'post__not_in' => array(121))); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>  
    
    <!-- Your stuff here -->
    
    <?php endwhile; endif; ?>
    Thread Starter eitai2001

    (@eitai2001)

    Thanks Doc4, your query_post code worked … needed to change it slightly though, but here is the version that worked:
    <?php query_posts(array(‘cat’=>array(64),’showposts’=>4,’post__not_in’ => array(121))); ?>

    @wej00, thanks but I needed the array, because I am actually using a variable in place of the 121 which checks for previous posts on the page to prevent duplicates.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Assistance with query_post code’ is closed to new replies.