在Wordpress中获取动态自定义帖子的PDF附件

时间:2018-07-07 09:21:18

标签: wordpress

请查看下面的代码,以获取有关自定义帖子类型的每个请求的PDF附件。如果我删除“ post_parent”,则可以正常显示所有pdf。

if(isset($_REQUEST['pdfpost']))
{
$date = $_POST['date'];

$res=mysql_query("SELECT ID FROM  `wp_posts` WHERE DATE_FORMAT(post_date,  
'%m/%d/%Y' ) =  '".$date."' AND post_type = 'pdf' AND post_status='publish'  
ORDER BY post_date DESC
LIMIT 0 , 1");
$post_id=mysql_fetch_array($res);
$pid = $post_id['ID'];
display_images_in_list1($pid);
exit();
}
function display_images_in_list1($pid) {
$imgid=$pid;

if($imgid!= "")
{       

if($images = get_posts(array(
    'post_parent'    => $imgid,
    'post_type'      => 'attachment',
'post_status' => 'inherit',
    'numberposts'    => -1, // show all
    'post_mime_type' => 'application/pdf',
            'orderby'        => 'title',
            'order'           => 'ASC',
))) {

$i = 1;    

foreach($images as $image) {
.......
 }
     }

0 个答案:

没有答案