我在页面上附有图库。在该页面上,我正在运行以下查询:
$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
)
);
我已经尝试了很多方法,由于某种原因,我无法获得附件以退回。我在这里错过明显的东西吗?
更新*
感谢Wok为我指明了正确的方向。
原来我使用的是“状态”而不是“ post_status”。该法典在“附件”帖子类型的上下文说明中以“状态”为例。我更新了法典以引用“ post_status”。正确的代码如下:
$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
)
);
我想知道post_status设置为'null'与'inherit'有什么区别
—
Wok
'post_status' => 'inherit'
谢谢,您为我省下了很多痛苦!