arrays - wordpress/php get_attachment_url based on uid and post parent id -


still learning , feel few steps away, appreciate help!

have multiple child posts should each return attachment url based on child post uploaded. using array gather attachments uploaded. have somehow managed working, returns uploaded user, when return recent upload user. use of 'max' accomplish seems kick out error. fifth line bottom trouble spot. using post_date try , accomplish this, think id suffice well. thank input can provide.

            $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 $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 $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>';                                          }}}}                                           ; 

i ended using sql solve via solution below.

$audiolinks = "select id, post_author, post_parent, max(post_date), guid     ".$wpdb->prefix."posts     post_author='$user->id' , post_parent ='$pid' order 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>'; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -