Search code examples
wordpresstaxonomy

Get Posts from custom taxanomy


I want to get posts with custom taxonomy, you can check the code below ppctrainings is the custom taxonomy category and 94 is the id of category.

<?php 
$count = 0;
// this is the custom taxonamy ppctrainings the id is 94
$posts = get_posts('ppctrainings=94&numberposts=10'); 
foreach($posts as $post) { 
if($count == 3){
echo '</tr><tr >';
$count = 0; 
}
$count++;
?>

Solution

  • <?php
    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'sliders_category', // taxonomy category
                'field' => 'id',
                'terms' => '2' // category id
            )
        ),
        'post_type'=>'sliders',  //name of post type 
        'order'=>'ASC',
        'posts_per_page'=>10
    );
        query_posts($args);
        while ( have_posts() ) : the_post(); 
    ?>
    
     // your code for display  title and content
    
    <?php   
        endwhile; 
        wp_reset_query();
    ?>