I am working on a wordpress site with theme name flozo . It has a custom post type named work
.
I wanted to display the works in my template based on each category.
Here is the code:
<?php
$args = array( 'post_type' => 'work', 'posts_per_page' => 15 );
$loop = new WP_Query( $args );
$count = 0;
echo '<ul>';
while ( $loop->have_posts() ) : $loop->the_post();
$count++;
$class = ($count % 3 == 1) ? 'first' : '';
echo '<li class="'.$class.'">';
echo '<a href="';
the_permalink();
echo '">';
echo '<div class="overlay" style="background-color:'.ot_get_option( 'main_colour' ).';"></div>';
the_post_thumbnail('full');
echo '</a>';
echo '<br />';
echo '<h2><a href="';
the_permalink();
echo '">';
the_title();
echo '</a></h2>';
echo '<div class="entry-content">';
echo limit_words(get_the_excerpt(), '30');
echo '..</div>';
echo '</li>';
endwhile;
echo '</ul>';
?>
I've added
$args = array( 'post_type' => 'work', 'tag_ID' => 15 ,'posts_per_page' => 15 );
where 15
is the id of my category, but it didn't work
I've also tried
<?php
$catquery = new WP_Query( 'cat=15&posts_per_page=3' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul class="last-cat">
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(); ?> <p><?php the_title(); ?></p><span><?php echo get_the_date(); ?></span></a></li></ul>
<?php endwhile; ?>
which also didn't help.
Edit:
The category url is
The post type registration code is :
add_action('init', 'work_register');
function work_register() {
$labels = array(
'name' => _x('Work', 'post type general name'),
'singular_name' => _x('Work Item', 'post type singular name'),
'add_new' => _x('Add New', 'work item'),
'add_new_item' => __('Add New Work Item'),
'edit_item' => __('Edit Work Item'),
'new_item' => __('New Work Item'),
'view_item' => __('View Work Item'),
'search_items' => __('Search Work'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => array( 'slug' => 'work', 'with_front'=> false ), 'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'work' , $args );
register_taxonomy("categories", array("work"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => array( 'slug' => 'work', 'with_front'=> false )));
}
tag_ID
needs to betag_id
. – Alexander O'Mara