Wp_Query a custom post type by category.
-
Hi,
I have two custom post types venues and foodmenus. venues is used a cpt-onomy to foodmenus.
Now on venue page I want to show in the end of the page all the foodmenus that have as a cpt-onomy this venue.
This is my code.
<?php $venuetitle = get_the_title(); // WP_Query arguments $args = array ( 'post_type' => 'foodmenus', 'category_name' => $venuetitle ); ?> <?php // the query $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> <!-- end of the loop --> <!-- pagination here --> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php _e( 'Sorry, this venue does not serve food!' ); ?></p> <?php endif; ?>I always get the Sorry… message!
What is wrong with my code?
Can someone please help with that?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Wp_Query a custom post type by category.’ is closed to new replies.