Title: help with code for custom post category
Last modified: August 22, 2016

---

# help with code for custom post category

 *  [equinesites](https://wordpress.org/support/users/equinesites/)
 * (@equinesites)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/)
 * I know this topic has been covered a lot, but the code in the template I am using
   isn’t exactly the same as is covered in other forum posts, so looking for a little
   help.
 * I am trying to show only the category “American” from my Restaurants custom post
   list on my AMERICAN page. As it is now – the page is displaying ALL of the restaurants,
   not just the category I want. Here is the code I am using in my template, with
   my attempt at the category callout in bold:
 *     ```
       <?php
       /**
        * Template Name: Restaurants List American
        *
        */
       ?>
   
       <?php get_header(); ?>
       <?php $page_width = get_post_meta(get_the_ID(), 'wpl_sidebar_option', true); ?>
       <div id="main" class="site-main container_12">
         <div id="primary" class="content-area ml <?php if ( $page_width != 'off' ) { echo 'grid_9'; } else { echo 'grid_12'; } ?>">
           <div id="content" class="site-content">
   
           <?php // Display the default content
             if ( $post->post_content != '' ) { ?>
               <?php while ( have_posts() ) : the_post(); ?>
                 <article class="single">
                   <div class="entry-content">
                     <?php the_content(); ?>
                   </div>
                   <div class="clear"></div>
                 </article>
               <?php endwhile;
             } // End displaying the default content
           ?>
   
           <?php $args = array( 'post_type' => 'post_restaurants','post_status' => 'publish', 'posts_per_page' => ot_get_option('wpl_restaurant_per_page'), 'paged'=> $paged); ?>
          <strong> <?php query_posts('category_name=American'); ?></strong>
             <?php $wp_query = null; ?>
             <?php $wp_query = new WP_Query( $args ); ?>
             <?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
               <!-- Article -->
                 <article id="post-<?php the_ID(); ?>" <?php post_class('list'); ?>>
                   <?php if ( has_post_thumbnail() ) {?>
                     <figure>
                       <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">
                         <?php the_post_thumbnail('small-thumb'); ?>
                       </a>
                     </figure>
                   <?php } ?>
   
                   <h1 class="entry-header">
                     <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                   </h1>
   
                   <div class="short-description">
                     <p><?php echo wplook_short_excerpt(ot_get_option('wpl_restaurant_excerpt_limit'));?></p>
                   </div>
   
                   <div class="entry-meta">
                     <a class="read-more-button fleft" href="<?php the_permalink(); ?>" title="<?php _e('Read more', 'wplook'); ?>"><?php _e('Read more', 'wplook'); ?></a>
   
                   </div>
                   <div class="clear"></div>
                 </article>
   
             <?php endwhile; wp_reset_postdata(); ?>
             <?php else : ?>
               <p><?php _e('Sorry, no restaurants matched your criteria.', 'wplook'); ?></p>
             <?php endif; ?>
   
             <?php wplook_content_navigation('postnav' ) ?>
           </div>
         </div>
   
         <!-- Right Sidebar -->
         <?php if ($page_width != 'off') { ?>
           <div id="secondary" class="widget-area grid_3">
             <?php get_sidebar('restaurants'); ?>
           </div>
         <?php } ?>
   
         <div class="clear"></div>
   
       </div><!-- #main .site-main -->
       <?php get_footer(); ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Vassilis Mastorostergios](https://wordpress.org/support/users/silencerius/)
 * (@silencerius)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/#post-5431785)
 * The issue here is that you’re basically using 2 different queries.
    ** <?php 
   query_posts(‘category_name=American’); ?>** <?php $wp_query = null; ?> <?php 
   $wp_query = new WP_Query( $args ); ?>
 * Remove ** <?php query_posts(‘category_name=American’); ?>**
 * and a few lines above adjust the following:
 *  <?php $args = array( ‘post_type’ => ‘post_restaurants’,’post_status’ => ‘publish’,‘
   posts_per_page’ => ot_get_option(‘wpl_restaurant_per_page’), ‘paged’=> $paged,‘
   category_name’ => ‘American’); ?>
 * let me know if it works
 *  Thread Starter [equinesites](https://wordpress.org/support/users/equinesites/)
 * (@equinesites)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/#post-5431799)
 * Thanks for the suggestion, but it didn’t work. It returned the ‘sorry no posts
   matched your criteria’ response.
 * I tried moving the ‘category_name’ => ‘American’ around within that string of
   code, but then it just called all of the categories, not just the American. ???
 *  [Vassilis Mastorostergios](https://wordpress.org/support/users/silencerius/)
 * (@silencerius)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/#post-5431808)
 * Oh I see. This is a custom post type so I guess it also has a custom taxonomy
   associated, this is why category_name wouldn’t work.
 * Can you locate the name of that custom taxonomy?
 *  Thread Starter [equinesites](https://wordpress.org/support/users/equinesites/)
 * (@equinesites)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/#post-5431825)
 * Yes, it’s ‘taxonomy-wpl_restaurants_category.php’
 * and the code in that file is:
 *     ```
       <?php
       /**
        * The default Custom Post Restaurants Archive
        *
        */
       ?>
   
       <?php include_once 'archive-post_restaurants.php'; ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘help with code for custom post category’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [equinesites](https://wordpress.org/support/users/equinesites/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/help-with-code-for-custom-post-category/#post-5431825)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
