This question seems to have been asked in some varieties, But mine is quite specific.
I need to display the most recent post of all categories of a custom post type called "products". I need to display the category instead of the title and link to that cat's archive.
The problem is, What I am getting instead is only one post of that general post type. Any thoughts?
Here is my starting point:
<?php
$query = new WP_Query( array(
'posts_per_page' => 12,
'post_type' => 'products',
'post_status'=>'publish',
'orderby'=>'post_date',
'order' => 'DESC',
'cat' => $category->term_id,
'count'=>1,
));
if ( have_posts() ) : while ( $query->have_posts()) : $query->the_post(); ?>
<div class="col-sm-6 col-md-4">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="pos-rel"> <?php the_post_thumbnail('product', array('class' => 'img-responsive center-block')); ?><h3><?php the_title(); ?></h3></a>
<?php else : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="featured-products pos-rel"><!--<img class="img-responsive center-block" src="<?php echo THEME_DIR; ?>/img/default-thumb.png" alt="<?php the_title(); ?>" />--><img class="img-responsive " data-src="holder.js/100%174/auto" alt="Generic placeholder image"><h3><?php the_title(); ?></h3></a>
<?php endif; ?>
</div><!-- col-sm-6 -->
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div><!-- end row -->
<ul class="pager">
<li class="previous"><?php previous_posts_link(); ?></li>
<li class="next"><?php next_posts_link(); ?></li>
</ul>
<?php else : ?>
<h1>Not Found</h1>
<p><a href="<?php echo home_url(); ?>" title="Home">Click Here to return to the Home Page</a></p>
<?php endif; ?>
The custom post type was created via a 3rd plug into Super CPT Plugin
Here is the code:
add_action( 'after_setup_theme', 'setup_data_structures' );
function setup_data_structures() {
if ( ! class_exists( 'Super_Custom_Post_Type' ) )
return;
$products = new Super_Custom_Post_Type( 'products', 'Product', 'Products' );
# Test Icon. Should be a square grid.
$products->set_icon( 'suitcase' );
# Taxonomy test, should be like categories
$product_category = new Super_Custom_Taxonomy( 'product-category', 'Product Category', 'Product Categories', 'category' );
# Connect both of the above taxonomies with the post type
connect_types_and_taxes( $products, array($product_category) );
# Add a meta box with every field type
$products->add_meta_box( array(
'id' => 'product-fields',
'context' => 'normal',
'fields' => array(
'client-name' => array('column' => true ),
'product-description' => array( 'type' => 'wysiwyg' )
)
) );
$products->add_to_columns( 'product-category' );