Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having a problem displaying filtered category list pages. I want to be able to only show the current category, not all of the posts from "my categories". i.e. www...com/mycategories/category-3/ would only show posts in category page. Here is what I have but it seems to display all the categories in the taxonomy-mycategories.php page.

Template page:

  <?php 
            $wp_query = null; $wp_query = $temp;
            $temp = $wp_query;
            $wp_query= null;
            $wp_query = new WP_Query();
            $wp_query->query("post_type=business&category_name=" . $_GET["category"] . "&". $catinclude ."&paged=".$paged.'&showposts=20'); 
            if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
                <?php the_title() ?>
  <?php endwhile; ?>

functions.php:

/******************
//  Business
******************/

function my_custom_post_business() {
    $labels = array(
        'name'               => _x( 'business', 'post type general name' ),
        'singular_name'      => _x( 'business', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New business' ),
        'edit_item'          => __( 'Edit business' ),
        'new_item'           => __( 'New business' ),
        'all_items'          => __( 'All business' ),
        'view_item'          => __( 'View business' ),
        'search_items'       => __( 'Search business' ),
        'not_found'          => __( 'No business found' ),
        'not_found_in_trash' => __( 'No business found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'business'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our business and business specific data',
        'public'        => true,
        'hierarchical'      => true,
        'show_ui'           => true,
        'show_in_nav_menus' => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
        'rewrite' => array(
            'slug' => 'business',
            'with_front' => false
            ),
        //'taxonomies' => array('category'),
    );
    register_post_type( 'business', $args );

}
add_action( 'init', 'my_custom_post_business' );



/** add categories for custom post type */
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
    register_taxonomy( 'mycategories', 'business', array( 'hierarchical' => true, 'label' => 'Business Categories', 'query_var' => true, 'rewrite' => true ) );
}
share|improve this question
    
Don't you mean archive page rather then template page? Where multiple taxonomy types are displayed together. –  Brad Dalton Feb 4 at 17:06
add comment

3 Answers

Use the following code:

<?php
if (have_posts()):
    while (have_posts()):
        the_post();
?>


<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<?php
        if ($content != 'no') {
            the_excerpt();
        }
    endwhile;
endif;
?>
share|improve this answer
    
sorry maybe I wasn't clear in my explanation. My post type is business and I need to dynamically get the category. So if I am on main category page and filter down into a single category by clicking "My first category" I would like posts to only show from "My first category" which I believe to be stored in "taxonomy-mycategories.php" but I could be mistaken. –  Lukasz Feb 8 '13 at 18:29
    
I updated my code and use it in your taxonomy-mycategories.php –  Genxer Feb 8 '13 at 21:28
    
still doesn't seem to work :( –  Lukasz Feb 11 '13 at 18:08
add comment

Your explanations are still far from clear. Is this what you want? Assuming the code goes into the category.php page.

<?php

$cat = get_query_var('cat'); // get current category
$yourcat = get_category($cat);

// now get all 'business' posts that are in the current custom taxonomy 
query_posts( array( 'post_type' => 'business', 'mycategories' => $yourcat->slug ) ); 

if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
  <h3><?php the_title(); ?></h3>
  <?php the_content(); ?>
<?php endwhile; endif; wp_reset_query(); ?>

Note: untested code.

share|improve this answer
    
maybe this will be more clear: ottawakent.com/news/business-feed when you click "category 1" you only get posts that are in that category which should be the first post. I have your code currently implemented and it seems to pull all the posts in the custom post type and not the specific category. –  Lukasz Feb 8 '13 at 20:08
add comment

Bit hard to understand exactly what you want but why can't you use pre_get_posts and customize the conditionals.

add_action( 'pre_get_posts', 'cpt_portfolio_items' );
function cpt_portfolio_items( $query ) {

if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'business' ) ) {
    $query->set( 'posts_per_page', '1' );
    }

}

Or something like this if i really understood exactly what you want

add_action( 'pre_get_posts', 'tax_portfolio_items' );
function tax_portfolio_items( $query ) {

if( $query->is_main_query() && !is_admin() && is_tax( 'tax-name' ) ) {
    $query->set( 'posts_per_page', '1' );
    }

}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.