• Hi guys,

    I’ve been coding for 13 hours today and I’m probably missing something here. What I’m trying to do here is looping trough all the posts of one taxonomy, then get the terms of each post from the other taxonomy and put them in an array. If I echo $termname in the following code it works; it shows a list of every term. If I try to push them in an array, only the last term seems to be in the array.

    $query = new WP_Query( $args );
    
            if ( $query->have_posts() ) {
                    while ( $query->have_posts() ) {
                            $query->the_post();
    
                                    $terms = get_the_terms( $post->ID, 'vendor' );
    
                                            $stack = array();
                                            foreach( $terms as $term ) {
    
                                                    $termname = $term->name;
                                                    array_push($stack, $termname);
                                            }
                    }
            } else {
                    // no posts
            }
    
    wp_reset_postdata();
    
    print_r($stack);

    ($args are set and correct)

    http://pastebin.com/Zf9GbXLe

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Using array_push in loop to put taxonomy terms in an array, can't get it to work’ is closed to new replies.