我想构造一个查询来显示自定义帖子(“podcast”)的列表,以及它们各自附件的URL。每个自定义post\\u类型(“podcast”)都有1个附件(属于其post\\u父级的mp3文件)。我想要一个无序的列表,显示播客的标题,以及它的附件url(附件的guid),如下所示:
<ul>
<li>Podcast Title - http://..../podcast.mp3</li>
我通过wp查询实现了这一点:<?php query_posts(\'showposts=1&post_type=podcasts\'); ?>
<ul>
<?php while (have_posts()): the_post(); ?>
<li><?php the_title(); ?><br>
<?php
$args = array( \'post_type\' => \'attachment\', \'post_parent\' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo $attachment->guid;
}
} ?>
</li>
<?php endwhile; ?>
</ul>
但我想知道如何使用原始SQL查询进行解决。我尝试了太多的问题,这让我头晕目眩-任何帮助都将是惊人的!*编辑:决定同意约翰对WordPress查询的建议。谢谢你,我相信其他人将来也会觉得这很有用。