wordpress/php基于uid和post父id获取附件url
我仍在学习,感觉离我只有几步之遥,所以我感谢你的帮助 有多个子帖子,每个帖子都应该根据该子帖子上传的内容返回一个附件url。使用数组收集已上载的附件。我设法让它工作,但它返回所有从该用户上传的内容,而我希望它只返回该用户最近上传的内容。任何使用“max”来实现这一点似乎都是一个错误。底部第五行是故障点。我正在使用post_date来尝试并实现这一点,但我认为ID也足够了。感谢您提供的任何意见wordpress/php基于uid和post父id获取附件url,php,arrays,wordpress,max,Php,Arrays,Wordpress,Max,我仍在学习,感觉离我只有几步之遥,所以我感谢你的帮助 有多个子帖子,每个帖子都应该根据该子帖子上传的内容返回一个附件url。使用数组收集已上载的附件。我设法让它工作,但它返回所有从该用户上传的内容,而我希望它只返回该用户最近上传的内容。任何使用“max”来实现这一点似乎都是一个错误。底部第五行是故障点。我正在使用post_date来尝试并实现这一点,但我认为ID也足够了。感谢您提供的任何意见 $exclude = array(); $args = arr
$exclude = array();
$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $pid,
'numberposts' => -1,
'post_status' => null,
);
$attachments = get_posts($args);
foreach($attachments as $att) $exclude[] = $att->ID;
$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $pid,
'post_author' => $uid,
'ID' => $pkey,
'exclude' => $exclude,
'numberposts' => -1,
'post_status' => null,
);
$attachments = get_posts($args);
if(count($attachments) == 0) echo __('No project files.','ProjectTheme');
foreach($attachments as $at) {
if($at->post_author == $user->ID) {
if($at->post_parent == $row->pid) {
if($at->post_date == $at['max(post_date)']) {
$fileName = wp_get_attachment_url($at->ID);
echo '<div>'. mp3j_put('[mp3j track="' . $fileName . '" flip="y"]').'</div><br>';
}}}}
;
$exclude=array();
$args=数组(
“订单”=>“ASC”,
“post_类型”=>“附件”,
“post_mime_type”=>“image”,
“post_parent”=>$pid,
“numberposts”=>-1,
“post_状态”=>null,
);
$attachments=get_posts($args);
foreach($attaches as$att)$exclude[]=$att->ID;
$args=数组(
“订单”=>“ASC”,
“post_类型”=>“附件”,
“post_parent”=>$pid,
“post_author”=>$uid,
'ID'=>$pkey,
“排除”=>$exclude,
“numberposts”=>-1,
“post_状态”=>null,
);
$attachments=get_posts($args);
if(count($attachments)==0)echo ___;('No project file.','ProjectTheme');
foreach(附件为$at){
如果($at->post_author==$user->ID){
如果($at->post\u parent==$row->pid){
如果($at->post_date==$at['max(post_date)'){
$fileName=wp\u get\u attachment\u url($at->ID);
回显'.mp3j_put('[mp3j track=“'.$fileName.''”flip=“y”]')。
;
}}}}
;
我最终使用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>';
$audiolinks=“选择ID、发布作者、发布父项、最大值(发布日期)、guid
从“$wpdb->prefix.”帖子
其中post_author='$user->ID',post_parent='$pid'order by ID DESC';
$audiolink=$wpdb->get_结果($audiolinks);
$filelink=wp\u get\u attachment\u url($audiolink[0]->ID);
$fileauthor=$user->user\u登录;
$filetitle=$post->post\u title;
回声“
. mp3j_put(“[mp3j track=“”.$filelink.”title=“播放试听:”
.$fileauthor.-“$post->post\u标题
“'flip=“y”]”);