Stuck trying to call in custom post types into wordpress

44 views Asked by At

Evening all.

I need a little help. I have the following code which brings in a list of portfolios, and places them on a page in a grid format. At present the code brings in all the portfolio types (of which there are 3, divided into different categories). Is there a way I can edit the code so that I can bring in just one category type?

I have tried the following:

<?php query_posts( array( 'post_type' => 'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12));

but it displays a blank page.

If I remove:

 'category_name' => 'news',

it returns a page will all the categories listed. I have checked the category name and all is correct but I'm clearly missing something.

I would be greatful if anyone could help.

Many thanks

The full code is:

<?php /* Template Name: Modular Gallery */ ?>
<?php get_header(); ?>
<div id="folio-wrap">
  <ul id="portfolio-list" class="centerrow">
    <?php query_posts( array( 'post_type'=>'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12)); if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    <?php $large_image=w p_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' ); $large_image=$ large_image[0]; $another_image_1=g et_post_meta($post->ID, 'themnific_image_1_url', true); $video_input = get_post_meta($post->ID, 'themnific_video_url', true); ?>
    <li id="post-<?php the_ID(); ?>" class="centerfourcol item_full">
      <span class="imgwrap">
            <?php the_post_thumbnail('folio',array('title' => "")); ?>
            <a class="hoverstuff-zoom" rel="prettyPhoto[gallery]" href="<?php if($video_input) echo $video_input; else echo $large_image; ?>"><i class="icon-zoom-in"></i></a>
            <a class="hoverstuff-link" href="<?php the_permalink(); ?>"><i class="icon-link"></i></a>
            </span> 
      <div style="clear:both"></div>
      <h3><a href="<?php the_permalink(); ?>"><?php echo short_title('...', 6); ?></a></h3>
      <?php echo themnific_excerpt( get_the_excerpt(), '290'); ?>
    </li>
    <!-- #post-<?php the_ID(); ?> -->
    <?php endwhile; endif; ?>
  </ul>
  <div class="clear"></div>
  <div class="pagination">
    <?php pagination( '«', '»'); ?>
  </div>
  <?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>

1

There are 1 answers

1
Claudiu Creanga On

Your code should work if "news" is your category SLUG, not necessary the name.

But on some older versions of wordpress there is a bug with category_name in query_posts, try it with cat_name