• I want to get a random post that is only in one category, I thought I would be able to exclude those that are in more than one category by using the exclude cat#. Like so

    <?php
    $args = array( 'numberposts' => 1, 'category' => '4' , 'orderby' => 'rand' , 'exclude' => '7' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<div class="rand-posts"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a><br /><b>Comida</b> / <?php the_title(); ?></div>
    <?php endforeach; ?>

    But it doesn’t seem to work. In this example I only want to get posts that are only in cat 4, and not 7. (if a post is in both cat 4 and 7 exclude).

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Get post from only one category’ is closed to new replies.