Checking for two categories in query_posts

How can I check two category_name values in the following query_post?

 <?php query_posts('category_name=recent-work&posts_per_page=1');
   if (have_posts()) : while (have_posts()) : the_post(); ?>

So that it reads something like this:

Read More
 <?php query_posts('category_name=recent-work&&category_name=plumbing&posts_per_page=1');
   if (have_posts()) : while (have_posts()) : the_post(); ?>

Many thanks.

EDIT:

<?php
        $querySimilarWork = new WP_Query( array(
            'tax_query' => array(
                array(
                    'taxonomy' => 'categories',
                    'field' => 'slug',
                    'terms' => array( 'recent-work', 'plumbing' )
                )
            ),
            'posts_per_page' => 4
        );
    ?>

EDIT:

If I now query this WP_query, it doesn’t return anything?

<?php while ($querySimilarWork->have_posts()) : $querySimilarWork->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>   
    </li>
 <?php endwhile; ?>

Related posts

1 comment

  1. Don’t use query_posts. Use WP_Query, and use it’s tax_query.

    $query = new WP_Query( array(
        ...
        'tax_query' => array(
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array( 'recent-work', 'plumbing', 'cat3' )
            )
        ),
        'posts_per_page' => 1
        ...
    );
    

Comments are closed.