Support » Developing with WordPress » post query with custom taxonomy

  • Resolved janbrokes

    (@janbrokes)


    Hello,

    could you please help me to change this simple query
    `<?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>`

    to show only posts from custom taxonomy “typ” and its term “example 1”

    thank you very much

Viewing 1 replies (of 1 total)
  • Subrata Sarkar

    (@subrataemfluence)

    This should work:

    <?php
    $args = array(
    'post_type' => 'your_post_type', // if you want to further filter by post_type
    'tax_query' => array(
        array(
        'taxonomy' => 'type',
        'field' => 'term_id',
        'terms' => 37 // you need to know the term_id of your term "example 1"
         )
      )
    );
    $query = new WP_Query( $args ); ?>
    
    while ( query->have_posts() ):
      $query->the_post();
      ...
    endwhile;

    Let me know if this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘post query with custom taxonomy’ is closed to new replies.