Obtengo una lista de todas las imágenes de la siguiente manera:
$the_query = new WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => -1, ) );
Pero estoy tratando de obtener solo aquellos que están cargados en una publicación en mi sitio web.
No se adjuntan imágenes a una publicación específica, pero se excluyen aquellas que no aparecen en ninguna publicación.
Todo lo que tienes que hacer es pegar el siguiente código dentro de un bucle.
$args = array( 'post_parent' => get_the_ID(), // your post id 'post_type' => 'attachment', 'numberposts' => -1, // show all 'post_status' => 'any', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC' ); $images = get_posts($args); if($images) { ?> <img src="<?php echo wp_get_attachment_url($image->ID); ?>" /> <?php } ?>
Creo que post_mime_type no es correcto.
$args = array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image/gif', ); $query = new WP_Query( $args );
¡Espero que esto ayude!