[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
On a previous site, I was able to display attachments to a post, on a page using:
<?php
function my_attachments( $attachments )
{
$fields = array(
array(
'name' => 'title', // unique field name
'type' => 'text', // registered field type
'label' => __( 'Title', 'attachments' ), // label to display
'default' => 'title', // default value upon selection
),
array(
'name' => 'categories', // unique field name
'type' => 'text', // registered field type
'label' => __( 'Add your categories', 'attachments' ), // label to display
'default' => 'categories', // default value upon selection
),
array(
'name' => 'embed', // unique field name
'type' => 'text', // registered field type
'label' => __( 'Video Embed (paste your video url e.g. http://www.youtube.com/embed/BPTT )', 'attachments' ), // label to display
'default' => 'embed', // default value upon selection
),
array(
'name' => 'description', // unique field name
'type' => 'textarea', // registered field type
'label' => __( 'Add a description of the video', 'attachments' ), // label to display
'default' => 'description', // default value upon selection
),
);
$args = array(
// title of the meta box (string)
'label' => 'Video Attachments',
// all post types to utilize (string|array)
'post_type' => array( 'post', 'full' ),
// meta box position (string) (normal, side or advanced)
'position' => 'normal',
// meta box priority (string) (high, default, low, core)
'priority' => 'high',
// allowed file type(s) (array) (image|video|text|audio|application)
'filetype' => 'null', // no filetype limit
// include a note within the meta box (string)
'note' => 'Attach files here!',
// by default new Attachments will be appended to the list
// but you can have then prepend if you set this to false
'append' => true,
// text for 'Attach' button in meta box (string)
'button_text' => __( 'Attach Video Files Here', 'attachments' ),
// text for modal 'Attach' button (string)
'modal_text' => __( 'Attach', 'attachments' ),
// which tab should be the default in the modal (string) (browse|upload)
'router' => 'browse',
// fields array
'fields' => $fields,
);
$attachments->register( 'my_attachments', $args ); // unique instance name
}
Hello,
On a previous site, I was able to display attachments to a post, on a page using:
<?php
function my_attachments( $attachments ) { $fields = array( array( 'name' => 'title', // unique field name 'type' => 'text', // registered field type 'label' => __( 'Title', 'attachments' ), // label to display 'default' => 'title', // default value upon selection ),
);
$args = array(
);
$attachments->register( 'my_attachments', $args ); // unique instance name }
add_action( 'attachments_register', 'my_attachments' );?>
$attachments = new Attachments( 'my_attachments' );
$search_args = array( 'instance' => 'my_attachments', // search 'attachments' instance 'fields' => array( 'categories' ), // search the 'caption' field only ); $attachments->search( 'video', $search_args ); if( $attachments->exist() ) while( $attachments->get() ) iframe width="285" height="256" src="http://www.youtube.com/embed/'.$attachments->field('embed').'" frameborder="0" allowfullscreen
In my recent attempt, I cant.
It displays fine when I use: $attachments = new Attachments( 'my_attachments', 103 );
Any thoughts?