Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
Get all images attached to any post

I am getting a list of all the images the following way:

$the_query = new WP_Query( array(
  'post_type'       => 'attachment',
  'post_mime_type'  => 'image',
  'post_status'     => 'inherit',
  'posts_per_page'  => -1,
 ) );

But I'm trying to get only those who are uploaded to a post on my website.

Not images attached to a specific post but exclude those who aren't featured on any post.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

All you have to do is paste the following code inside a loop.

$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
}
?>
over 4 years ago · Santiago Trujillo Denunciar

0

I think the post_mime_type is not correct.

$args = array(
    'post_type'  => 'attachment',
    'post_status'    => 'inherit',
    'post_mime_type' => 'image/gif',
);

$query = new WP_Query( $args );

Hope this helps!

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda