wp-query – ¿Roto? WP_Query y "adjunto" como tipo de publicación

Pregunta:

Tengo una galería adjunta a una página. En esa página, estoy ejecutando la siguiente consulta:

$events_gallery = new WP_Query( // Start a new query for our videos
array(
    'post_parent' => $post->ID, // Get data from the current post
    'post_type' => 'attachment', // Only bring back attachments
    'post_mime_type' => 'image', // Only bring back attachments that are images
    'posts_per_page' => '3', // Show us the first three results
    'status' => 'inherit', // Inherit the status of the parent post 
    'orderby' => 'rand', // Order the attachments randomly  
    )
);

He experimentado bastantes formas y, por alguna razón, no puedo conseguir que regresen los archivos adjuntos. ¿Me estoy perdiendo algo obvio aquí?

Actualizar*

Gracias a Wok por indicarme la dirección correcta.

Resulta que estaba usando "status" en lugar de "post_status". El códice había utilizado "estado" como ejemplo en su explicación en contexto del tipo de publicación "adjunto". En su lugar, actualicé el códice para hacer referencia a "post_status". El código correcto es el siguiente:

$events_gallery = new WP_Query( // Start a new query for our videos
array(
    'post_parent' => $post->ID, // Get data from the current post
    'post_type' => 'attachment', // Only bring back attachments
    'post_mime_type' => 'image', // Only bring back attachments that are images
    'posts_per_page' => '3', // Show us the first three results
    'post_status' => 'inherit', // Attachments default to "inherit", rather than published. Use "inherit" or "any".
    'orderby' => 'rand', // Order the attachments randomly  
    )
);  

Respuesta:

Estos son los parámetros de consulta que uso … funciona para mí cuando reviso los resultados

array(
    'post_parent' => $post->ID,
    'post_status' => 'inherit',
    'post_type'=> 'attachment',
    'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png'                  
);

Para obtener más detalles, consulte la documentación oficial de los parámetros de estado de WP_Query

Leave a Comment

Your email address will not be published. Required fields are marked *

web tasarım