wordpress / php get_attachment_url基于uid和post parent id

时间:2016-01-16 10:12:08

标签: php arrays wordpress max

仍在学习,感觉我只有几步之遥,所以我感谢你的帮助!

根据子帖子上传的内容,有多个子帖子,每个帖子都应返回一个附件网址。使用数组收集上载的附件。我已经设法让它工作,但它返回从该用户上传的所有,当我希望它只返回该用户的最新上传。任何使用' max'实现这一点似乎是一个错误。底部的第五行是故障点。我正在使用post_date来尝试实现这一点,但我认为ID也足够了。感谢您提供的任何意见。

select TOP 10  Count(pid) as ratio, PCountry, datediff(YEAR,pDOB,GETDATE()) as ageInYear 
where datediff(YEAR,pDOB, GETDATE()) >  40 
Group By datediff(YEAR,pDOB, GETDATE()),PCountry

1 个答案:

答案 0 :(得分:0)

我最终使用SQL通过以下解决方案解决了这个问题。

$audiolinks = "select ID, post_author, post_parent, max(post_date), guid
    from ".$wpdb->prefix."posts
    where post_author='$user->ID' AND post_parent ='$pid' order by id DESC";
$audiolink  = $wpdb->get_results($audiolinks);
$filelink = wp_get_attachment_url($audiolink[0]->ID);
$fileauthor = $user->user_login;
$filetitle = $post->post_title;
echo '<div style="padding-top: 10px">'
    . mp3j_put('[mp3j track="' . $filelink . '" title="Play Audition: '
    . $fileauthor . " - " . $post->post_title
    . '" flip="y"]').'</div><br>';