1

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

1 Answer 1

2

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.

0

Your Answer

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

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