Javascript,Nodejs,MongodDB,WordPress,CSS,PHP

LightBlog

Monday, August 27, 2018

How to display post by categories or taxonomy

Display post by categories or taxonomy in wordpress.
where: cursussencat categories or taxonomy name,


<?php $terms = get_terms("cursussencat", array("hide_empty" => true)); ?>

<?php  // print_r( $terms); ?> 

<?php foreach ($terms as $getterm){ ?>  
                      
<h2><?php echo $getterm->name ?></h2>

<?php
$args = array(
    "posts_per_page"    => 999,
    "post_count"        => 9999,
    "post_type"         => 'cursussenpage', // this post type
    "order"             => "DESC",
    'tax_query' => array(
        array(
            'taxonomy' => 'cursussencat', // taxonomy name
            'field' => 'ID',
            'terms' => $getterm->term_id
        )
    )         
);
$loop = new WP_Query($args); // wp query loop
?>
<?php if($loop->have_posts()): ?>
<?php while($loop->have_posts()): $loop->the_post(); ?>
<div class="item">
   
    </h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
   
    <?php the_content(); ?>
   
</div>                   
<?php endwhile; ?>

<?php endif; wp_reset_query(); ?>
<?php } ?>



No comments:

Post a Comment