I have trued this to query my posts and while it does exclude cat=157 it does hold specific to cat=3. It seems to be ignoring the first parameter in favor of the second.
query_posts('cat=3&cat-157')
Does anyone know how to do this?
Thanks!
I have trued this to query my posts and while it does exclude cat=157 it does hold specific to cat=3. It seems to be ignoring the first parameter in favor of the second.
query_posts('cat=3&cat-157')
Does anyone know how to do this?
Thanks!
A bit confused by your question as query_posts('cat=3'); will get posts in category 3 and exclude every other category.
I have two categories, 3 and 157. Some posts are only in 3 while others are in 3 and 157. On the landing page I am pulling all category 3 posts including those that also have category 157.
On another page I only want to pull posts that are exclusively in category 3 and not the ones that are also in category 157.
I tried to solve this with the following code:
query_posts('cat=3&cat-157')
My thought was that I could pull only category 3 while specifically excluding category 157 and thus filter out the posts that are in both 3 and 157.
I hope this makes a bit more sense.
Try something like this:
<?php
$args=array(
'cat' => 3,
'category__not_in'=> array(157),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>This topic has been closed to new replies.