• 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?

    https://ww.wp.xz.cn/plugins/cpt-onomies/

Viewing 1 replies (of 1 total)
  • Thread Starter bigdrop.gr

    (@bigdropgr)

    I figured it out!!

    Just in case anyone need this!!

    <?php
    $venuetitle = get_the_title();
    $args = array(
       'post_type' => 'foodmenus',
       'tax_query' => array (
          array (
             'taxonomy' => 'venues',
             'terms' => $venuetitle,
          )
       )
    );
    query_posts($args);
    if ( have_posts() ) : ?>
       <ul>
       <?php while ( have_posts() ) : the_post(); ?>
          <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
       <?php endwhile; ?>
       </ul>
    <?php endif;
    
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Wp_Query a custom post type by category.’ is closed to new replies.