WordPress.org

Ready to get started?Download WordPress

Forums

A Loop with Specific Category and Taxonomy (2 posts)

  1. the.green.timtam
    Member
    Posted 1 year ago #

    So, I'm trying to create a loop that displays everything of a post type 'photo-albums' in the category 'circus'. I am just using the standard built in category taxonomy. What I have at the moment is the following:

    <?php $album_loop = new WP_Query( array('category' => 'circus', 'post_type' => 'photo-albums', 'posts_per_page' => '10', 'orderby' => 'menu_order' ) ); ?>
    
    	 	<?php while ( $album_loop->have_posts() ) : $album_loop->the_post(); ?>

    This is displaying posts in all categories. What am I doing wrong?

  2. the.green.timtam
    Member
    Posted 1 year ago #

    Sorted - I found a solution online.

    <?php $args = array(
                        'post_type' => 'photo-albums',
                        'posts_per_page' => 10,
                        'tax_query' => array(
                                               'relation' => 'AND',
                                               array(
                                                      'taxonomy' => 'category',
                                                      'field' => 'slug',
                                                      'terms' => array(
                                                                        'circus'
                                                                       )
                                                    )
                                            )
                      ) ;
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.