• Resolved Aldance

    (@aldance)


    Hello guys, I created a custom post type “awards” and then added a few categories under that post type. How would I go about in displaying the posts under category-1?

    This is the code that I have:

    <?php
      query_posts( array( 'post_type' => 'awards', 'categories' => 'restaurant' ) );
      if ( have_posts() ) : while ( have_posts() ) : the_post();
      ?>

    The post type is “awards”, the category is “restaurant”

    This kind of works, in the way that it displays the two latest posts under the post type “awards” but only one of the posts is under the category “restaurant”

Viewing 1 replies (of 1 total)
  • Thread Starter Aldance

    (@aldance)

    Ok, I’ve found the solution thanks to this post. Here’s the code that worked:

    <?php
    $args=array(
      'awards-type' => 'restaurant',
      'post_type' => 'awards',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thanks to MichaelH for the code.

Viewing 1 replies (of 1 total)
  • The topic ‘Created a custom post type added categories, want to display them but can't’ is closed to new replies.