Created
July 26, 2016 07:34
-
-
Save celticwebdesign/ae355a0661c3226b79f88962e927066a to your computer and use it in GitHub Desktop.
WordPress loop objects into array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$args = array( | |
'post_type' => 'products', | |
'post_status' => 'publish', | |
'posts_per_page' => -1 | |
); | |
$child_query = new WP_Query($args); | |
$brands_array = []; | |
if( $child_query->have_posts() ) : while ( $child_query->have_posts() ) : $child_query->the_post(); | |
$post_terms = wp_get_post_terms( get_the_id(), 'brands' ); | |
$object = new stdClass(); | |
$object->name = $post_terms[0]->name; | |
$object->slug = $post_terms[0]->slug; | |
array_push($brands_array,$object); | |
endwhile; endif; | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment