Tag Info

New answers tagged

0

Use this function get_attached_media $images = get_attached_media( 'image' ); You can also pass as a second parameter the ID of a post.


1

Great Snippet available here from the guys at CSS-Tricks: $thumb_id = get_post_thumbnail_id(); $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); $thumb_url = $thumb_url_array[0]; When I first tried this solution it kept throwing 'Missing Attachment' because I was referencing the post ID instead of the attachment ID. ...


0

You need need to update the allowed mime-types that WordPress has in its settings. For zip/rar files: function my_modify_mimes( $mimes ) { $mimes['zip'] = 'application/zip'; $mimes['rar'] = 'application/x-rar-compressed'; return $mimes; } add_filter( 'upload_mimes', 'my_modify_mimes' ); Also, if you are uploading from the front-end you ...


0

Edit: Sorry, I totally read over the specific file part of your question the first time around.. You should take a look at your $_FILES array to determine, if the mime type actually is application/zip, just because your file ends with .zip thats not necessarily true, or if and when what error is returned. You could and probably should - at least for ...


0

$attachment_id is simply the numerical ID assigned to any media you have uploaded. You can write: echo wp_get_attachment_image('1','large'); to display the large size of image attachment with ID of 1. You should setup a new query to get all of the attachment IDs associated with the current post, then you can get_posts('post_type=attachment') Check ...


0

Solved, thanks to this post by Mike Jolley (see 'Passing data to the uploader script').


0

Can I fix your code ? $uploaddir = wp_upload_dir(); $file = $_FILES[ ... whatever you have in your POST data ... ]; $uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] ); move_uploaded_file( $file['tmp_name'] , $uploadfile ); $filename = basename( $uploadfile ); $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = ...


0

Add the following condition before the file upload functionality - $allowedExts = array("pdf", "jpg", "png"); $temp = explode(".", $_FILES["attachment"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "image/pdf") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png")) && ...


0

You have to trigger a change event on your field, i.e. hrld_media_input.attr("value", ui.item.value).change();. This will ensure that attachment_fields_to_save will get triggered.


0

Most of the time you want to customize the output of different post (post, page, attachment or custom post type), you will want to use specific template files as it is easier to maintain. For example: single.php for standard post and defualt template for other post types with no specific tempalte file attachment.php for media attachements image.php for ...


0

You can make use of a conditional tag, in this case is_singular() would be fitting: is_singular('post') Returns true when viewing a regular post, because the $post_types parameter is set to it.


0

You could try wp_prepare_attachment_for_js($id) and return everything you need for attachement. You'll recive an array with this: id title filename url link alt author description caption name status uploadedTo date modified menuOrder mime type subtype icon dateFormatted nonces editLink sizes width height fileLength compat Check here: ...


3

I got curious about the SQL way of finding all posts without any attachments. Method #1 - Sub query with NOT IN Here's my first attempt to construct such a query: global $wpdb; $sql = " SELECT p1.ID, p1.post_title FROM {$wpdb->posts} p1 WHERE p1.post_type = 'post' AND p1.post_status = 'publish' ...


5

If you're comfortable with the complete opposite of the linked answer, you simply could use this query to fetch all posts that have an attachment and then use their IDs as the post__not_in parameter of \WP_Query: $attachment_args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', ...


1

I ended up modifying slightly to use data-filter instead of rel. Works perfectly and complies with standards. add_filter( 'get_image_tag', function( $html, $id ) { $dataFilter = array(); foreach( (array) get_the_category( $id ) as $cat ) { $dataFilter[] = $cat->slug; } return str_ireplace( ...


1

You can use add_attachment action to set a default value for a custom field: function set_default_meta_value_62481( $attachment_id ) { add_post_meta( $attachment_id, '_show_attach', '1' ); } add_action( 'add_attachment', 'set_default_meta_value_62481' );



Top 50 recent answers are included