WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the Media Library, when I go in to attach a media item to a post, I know I can use "Attach" to pull up the "Find Posts or Pages" pop up.

This brings the following list of post title, date and status.
find posts or pages results

I wonder if there is a way to have the results show the post ID as well?

It might have something to do with the find_posts_div function, but I'm not sure how to apply the proper filters.

share|improve this question
up vote 6 down vote accepted

You cannot do that with pure PHP. The table is created in wp-admin/includes/ajax-actions.php::wp_ajax_find_posts(), and there is no filter.

But look at the radio buttons:

name="found_post_id" value="' . esc_attr($post->ID)

You can print a script on the action admin_footer-upload.php that extracts the post ID from the values and adds a new column to the table.

Here is a working example as a plugin. The code is not exactly beautiful, but it works and it should speak for itself:

 * Plugin Name: Extend Media Find Posts Table

add_action( 'admin_footer-upload.php', 't5_add_id_to_post_search' );

function t5_add_id_to_post_search()
jQuery(function($) {
    // bind ajaxStop() to any unique element.
    $('#find-posts-submit').ajaxStop(function() {
        var table = $('#find-posts-response table');
        // add the heading
        $(table).find('thead tr').append($('<th>ID</th>').css('width', '2em'));
        // take ID from input and append as 'td'
        $(table).find('tbody tr').each(function(){
            $(this).append('<td>' + $(this).find('input').val() + '</td>');


enter image description here

share|improve this answer
Thanks, toscho. But I can't seem to hook into the content inside of this "found-posts" div. I've tried adding some echo statements to test, but nothing will show up. Any ideas? – Ginger Ngo Oct 31 '12 at 19:10
See my update. Tested, works. :) – toscho Oct 31 '12 at 23:37
+1 as I've never seen that modal/overlay before – kaiser Nov 1 '12 at 1:15
Holy crap that's amazing. Thanks so much for this! – Ginger Ngo Nov 2 '12 at 0:12

Your Answer


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.