WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I'm currently building a custom post type in Wordpress and I need to be able to list all attachments inside the edit screen.

I know how to do this on the front-end template, but anyone know the code to use or can be placed in the functions.php page for the custom post type?

Essentially, what I'm trying to do is list all attachments in a checkbox list, then allow the editor to select them to associate with a custom field.

Thanks! Troy

share|improve this question

You need to add a meta box and populate it with the post attachments. It is very similar to the front end code you would use, except you need to save the data.

On admin init:

add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args ); ?>

function custom_type_metabox($post) {
    $custom_box = get_post_meta();
    //get all the attachments for the post  and throw them in an array. 
  //populate a checkbox list with the attachments from your array
<input type="radio" name="custom_attach" value="any" <?php if ($somestring == 'attachment') echo "checked=1";?>> 
// then you need to save the data and pass it to the post using "save_post"
add_action('save_post', array('your_data'));
// add your function to verify and save data properly

This is just a simple non working example I wrote off the cuff because what your asking for is basically the same as writing a plugin, maybe this will lead you into the codex.

share|improve this answer
Thanks Wyck... I'll give this a try. – Troy Apr 6 '11 at 4:01

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.