Answers for "get_posts by term id"

PHP
1

how to get texonomy catogory wise post

$custom_terms = get_terms('custom_taxonomy');

foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'custom_post_type',
        'tax_query' => array(
            array(
                'taxonomy' => 'custom_taxonomy',
                'field' => 'slug',
                'terms' => $custom_term->slug,
            ),
        ),
     );

     $loop = new WP_Query($args);
     if($loop->have_posts()) {
        echo '<h2>'.$custom_term->name.'</h2>';

        while($loop->have_posts()) : $loop->the_post();
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
        endwhile;
     }
}
Posted by: Guest on July-14-2020
0

tax query by term id

<?php
$args = array(
'post_type' => 'recipe_cpt',
'tax_query' => array(
    array(
    'taxonomy' => 'recipe_tx',
    'field' => 'term_id',
    'terms' => 37
     )
  )
);
$query = new WP_Query( $args ); ?>
Posted by: Guest on December-09-2020

Browse Popular Code Answers by Language