I can’t figure how to get the ID of the custom taxonomy I’m using to loop through the custom post type called “test_values”.

function prefix_load_term_posts () {
    $term_slug = $_POST[ 'term' ];
    $args = array (
             'post_type' => 'test_values',
             'posts_per_page' => 1,
             'tax_query' => array(
              array(
                    'taxonomy' => 'test_value_category',
                    'field'    => 'slug',
                    'terms'    => $term_slug ,
               ),

              ),
         );

    global $post;

    $myposts = get_posts( $args );
    ob_start ();

    foreach( $myposts as $post ) : setup_postdata($post); ?>

    <?php endforeach; ?>

Anyone have any suggestions how to get this taxonomy ID within the loop?

2 s
2

You can try this function get_term_by($field, $value, $taxonomy, $output, $filter ) or

$termID = [];
$terms = get_the_terms($post->ID, 'taxonomy');
foreach ($terms as $term) {
    $termID[] = $term->term_id;
}

or get_queried_object_id()

Leave a Reply

Your email address will not be published. Required fields are marked *