WordPress.org

Ready to get started?Download WordPress

Forums

category__and in WP3.2.1 (5 posts)

  1. Colin Young
    Member
    Posted 2 years ago #

    I have just set up a query like this

    query_posts( array( 'category__and' => array(630,35)));

    I have articles that are in both categories but the page doesn't display anything.

    Can anyone please help?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Can you paste and submit the full code of the template file into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  3. Colin Young
    Member
    Posted 2 years ago #

    Hi

    Sorry about that.

    <?php
    		query_posts(array( 'category__and' => array(630,35)));
    		while (have_posts()) : the_post();
    		the_excerpt();
    		endwhile;
    ?>

    I got it working, it was a mistake on my part. However, now I want to replace the 650 in the array with the category slug without me having to put the ID in myself.

    Is that possible?

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    If this is on a category page you can get the current category with this:

    <?php
    $current_cat = get_query_var('cat');
    query_posts(array( 'category__and' => array($current_cat,35)));
    while (have_posts()) : the_post();
    the_excerpt();
    endwhile;
    ?>
  5. Colin Young
    Member
    Posted 2 years ago #

    That's excellent. I will try that when I get home.

    I haven't heard of the get query var yet so will have a look at that as well.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.