Skip to content

Instantly share code, notes, and snippets.

@zazk
Last active October 30, 2017 17:25
Show Gist options
  • Select an option

  • Save zazk/dc0943daeb074f2a4e62f6a781f75d85 to your computer and use it in GitHub Desktop.

Select an option

Save zazk/dc0943daeb074f2a4e62f6a781f75d85 to your computer and use it in GitHub Desktop.
Taxonomy Recursive
<?php
$namelinea = $_POST['termname'];
$args = array(
'post_type' => 'productos',
'posts_per_page' => 3,
'taxonomy' => 'linea-maquinaria',
'term' => $namelinea, //slug de terminos
'nopaging' => true, // to show all posts in this taxonomy, could also use 'numberposts' => -1 instead
);
$args = new WP_Query($args);
while($args->have_posts()): $args->the_post();
$images = [];
if( have_rows('galeria_de_imagenes') ):
while( have_rows('galeria_de_imagenes') ): the_row();
$images[] = get_sub_field('imagen_producto');
endwhile;
endif;
$post_data[] = array(
'titulo' => get_the_title(),
'imagen' => $images
);
$images = null;
endwhile; wp_reset_postdata();
echo json_encode( $post_data );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment