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 duplicated a portfolio column page template ... On this page I want to show only one category , instead of all categories... I tried a lot, but couldn't get it worked...

this is the original code to show all categories:

<div class="container">

    <ul id="ublportfolio" class="grid cs-style-3">

        <?php 
            query_posts( array( 'post_type' => 'ublalfieportfolio', 'posts_per_page' => -1) );
            if ( have_posts() ) : while ( have_posts() ) : the_post(); 

            global $post;
            $terms = get_the_terms($post->ID, 'ublalfieportfolio-categories');
            $taxclassadd = '';
            foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

            $taxclass = 'thisportfolioitem twocol' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
        ?>

        <li <?php post_class($taxclass); ?> id="post-<?php the_ID(); ?>" data-category="<?php echo $str; ?>">
            <figure>

                <?php if(has_post_thumbnail()) { 
                $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false);
                if($thumbnail['1'] > 1024){$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large', false);} ?>
                <img src="<?php echo $thumbnail['0']; ?>" alt="<?php the_title(); ?>">
                <?php } ?>

                <figcaption>
                    <h3><?php the_title(); ?></h3>
                    <span><?php if($post->post_excerpt){$getcontent = get_the_excerpt();echo $getcontent;} ?></span>
                    <a href="<?php the_permalink(); ?>"><?php _e('View Item','ublalfie'); ?></a>
                </figcaption>

            </figure>
        </li>

        <?php endwhile; endif; ?>

    </ul>

</div>

for example I only want to show : the category-slug = "parketten" and ID = 3

I tried this:

<?php 
          query_posts( array( 'post_type' => 'ublalfieportfolio', 'category_name' => 'terrassen', 'posts_per_page' => -1) );
          if ( have_posts() ) : while ( have_posts() ) : the_post(); 

          global $post;
          $terms = get_the_terms($post->ID, 'parketten');
          $taxclassadd = '';
          foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

          $taxclass = 'span4 portfolioitem text-center' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
      ?>

result : shows nothing

<?php 
            query_posts( array( 'post_type' => 'ublalfieportfolio', 'category' => array(3), 'posts_per_page' => -1) );
            if ( have_posts() ) : while ( have_posts() ) : the_post(); 

            global $post;
            $terms = get_the_terms($post->ID, 'parketten');
            $taxclassadd = '';
            foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

            $taxclass = 'span4 portfolioitem text-center' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
        ?>

result: shows all categories..

Can someone please give me a solution... thank you very much

share|improve this question
    
Are you sure it is a category and not custom taxonomy? In third section of code you should use 'cat' => 3 instead of 'category' => array(3) –  Vinod Dalvi Aug 3 '13 at 10:26
    
thank you.. To be honest .. I think it is a custom taxonomy category.. would that be the problem? how would the code be? –  shopowner Aug 3 '13 at 11:13
    
I tried with 'cat' => 3 and result: nothing shows up... –  shopowner Aug 3 '13 at 11:17
    
parketten = taxonomy=ublalfieportfolio-categories&tag_ID=3&post_type=ublalfieportfolio –  shopowner Aug 3 '13 at 11:18
add comment

1 Answer

up vote 0 down vote accepted

You should not use category parameter to query custom taxonomy instead you should use tax_query parameter or directly custom taxonomy name as shown in the following query.

query_posts( array( 'post_type' => 'ublalfieportfolio', 'ublalfieportfolio-categories' => 'parketten', 'posts_per_page' => -1) );

Refer this page to know how to use custom taxonomy parameter in custom query.

share|improve this answer
    
thank you, i am looking for the taxonomy name... –  shopowner Aug 3 '13 at 11:32
    
Woohoo! You did the trick man! Great! Thank you so much! –  shopowner Aug 3 '13 at 11:45
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.