Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Taxonomy WP_Query

I am trying to display a custom post type that has custom taxonomy, but I am not having any luck. Nothing is showing up. I appreciate any help.

Post type = gallery

Custom Taxonomy slug = photoarea

The 'photoarea' I want to display = fourth

enter image description here

<?php 

$args = array( 
               'post_type' => 'gallery', 
               'tax_query' => array(
                   array(
                        'taxonomy' => 'photoarea',
                        'field' => 'fourth', 
                        )
                ),
               'posts_per_page' => 10,
              );

$the_query = new WP_Query( $args );


if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

     the_post_thumbnail();

 endwhile; endif;

wp_reset_query();

?> 
like image 971
this_guy Avatar asked Nov 26 '22 09:11

this_guy


1 Answers

You may use below code snippet:

$the_query = new WP_Query( 'post_type=gallery&photoarea=fourth');

and then your while loop.

like image 51
nim Avatar answered Nov 29 '22 03:11

nim