1

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();

1 Answer 1

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. :)

4
  • 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...
    – v3nt
    Jan 23, 2012 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, 2012 at 15:07
  • @danielCrabbe I updated my answer with a link to some code you can benefit from.
    – Jared
    Jan 23, 2012 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).
    – v3nt
    Jan 24, 2012 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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