I created custom post and taxonomy. Now I want display post under category like below format.
- taxonomy name 1
- post 1
- post 2
- post 3
- post all
- taxonomy name 2
- post 1
- post 2
- post 3
- post all
- taxonomy name 4
- post 1
- post 2
- post 3
- post all
And continue like that.
I found a code but that doesn’t work.
Code
<?php
$taxonomy = 'category';
$param_type = 'category__in';
$term_args=array(
'orderby' => 'name',
'order' => 'ASC');
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<div class="category section">
<h3><?php echo 'Category '.$term->name;?></h3>
<ul><?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
<?php}
}}
wp_reset_query(); // Restore global post data stomped by the_post().?>
so pls help me. how to fix it.
Thanks
I’m assuming you are trying to fetch any posts from Taxonomy
Category
.Please note that the
caller_get_posts
parameter is deprecated since 3.1. Always consult Codex for the latest code directions, and don’t use deprecated code.WP_Query()
– WordPress CodexYou can try this, you might want to move it inside your template instead of having it inside a function, make sure
$tax
is correct taxonomy, also change thepost_type
if you are not using native wordpress Post