Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

wondering if its possible to show the attachments admin list for videos by using a custom menu link?

Any pointers welcome! D.

add_action('admin_menu', 'mt_add_pages');
function mt_add_pages() {
    add_menu_page('Directors & Showreels', 'Directors & Showreels', 'manage_options', 'dsv_menu', 'wps_theme_func',null,2);
    $videos_page = add_submenu_page('dsv_menu', __('Videos','showreel_videos'),  __('Videos','showreel_videos'), 'edit_posts', 'sub-page-videos', 'display_showreel_videos');

}
function display_showreel_videos(){ ?>
     <div class="wrap"><h2>Videos</h2>
          <!-- get attachments by mime type ? (upload.php?post_mime_type=video ??)   -->
    </div><?
}

got this working with class TT_Example_List_Table extends WP_List_Table with help from links below... Looks fine but can't get edit or delete delete links to work properly.

$media_query = new WP_Query(
    array(
        'post_type' => 'attachment', // get attachments only
        'post_status' => 'inherit', // attachments are not 'published', so set it to inherit
        'posts_per_page' => -1, // display all
        'post_mime_type' => 'video' // grab files with the mime type 'video'
    )
);

$list = array();

foreach ($media_query->posts as $post) {

    $list[] = array('thumbnail'=>'', 'ID'=>$post->ID,'title'=>$post->post_title);

}

//Create an instance of our package class...
$testListTable = new TT_Example_List_Table();
$testListTable->setContent($list);
$testListTable->prepare_items();
$testListTable->display();
share|improve this question
add comment

1 Answer 1

I asked a similar question and got this answer, to query the DB for attachments and dump them into a list. This was the code that was provided to me:

$media_query = new WP_Query(
    array(
        'post_type' => 'attachment', // get attachments only
        'post_status' => 'inherit', // attachments are not 'published', so set it to inherit
        'posts_per_page' => -1, // display all
        'post_mime_type' => 'video' // grab files with the mime type 'video'
    )
);
$list = array();
foreach ($media_query->posts as $post) {
    $list[] = wp_get_attachment_url($post->ID);
}
// do something with $list here;

Hope this points you in the right direction. My question: Get All Images in Media Gallery?


EDIT: As far as displaying it in a table, I think you could truly benefit from digging through this code: http://wordpress.org/extend/plugins/custom-list-table-example/

It has a working example of using WP_List_Table in WordPress. I took one glance and knew it would be a good code to check out. :)

share|improve this answer
    
thanks Jared. I think the main issue i have is rendering the table. Just found WP_List_Table class but no clear examples on how to pass results into it... –  daniel Crabbe Jan 23 '12 at 12:48
    
In that case you will want to read codex.wordpress.org/Class_Reference/WP_List_Table and core.trac.wordpress.org/browser/tags/3.3.1//wp-admin/includes/… -- I will try and prepare a working example for you. –  Jared Jan 23 '12 at 15:07
    
@danielCrabbe I updated my answer with a link to some code you can benefit from. –  Jared Jan 23 '12 at 15:13
    
thanks Jared. Mostly working now and just a few niggles to work out (i.e. delete links doesn't n not sure how to specify it). –  daniel Crabbe Jan 24 '12 at 12:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.