Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Obtener todas las imágenes adjuntas a cualquier publicación

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.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

0

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!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!