Display posts from specific slug of the custom taxonomy in WordPress

Question

I have this piece of code, but what I really want to do is to get all post displayed from my taxonomy. Where do I place my taxonomy slug to make sure only a certain category posts are displayed? The category slug it’s let’s say “projects”. How to filter this category? Currently it seems that it displays all my posts on the page. Here is the code:

  $myterms = get_terms('units', 'orderby=none&hide_empty');    
  echo  $myterms[0]->name;


  foreach ($myterms as $term) :

    $args = array(
        'tax_query' => array(
            array(
                $term->slug,
            )
        )
    );
    
    //  assigning variables to the loop
    global $wp_query;
    $wp_query = new WP_Query($args);
    
    // starting loop
    while ($wp_query->have_posts()) : $wp_query->the_post();
    
    the_title();

    
    endwhile;
    
    endforeach;

0
Piotr Ciszewski 2 months 2022-12-14T15:20:24-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse