post_parent is 0 when uploading new files

The reason was the post_id key simply missing from the upload query. It was there for the normal posts, but was being omitted in the custom-post-type uploads. No idea why. The issue had something to do with the javascript uploader settings. So I’ve asked another question regarding the pluploader here and have managed to find … Read more

Get the title and URL of the attachment parent post

All attachments has got a post parent which you can access with $post->post_parent inside the loop or get_queried_object()->post_parent outside the loop on your image.php or similar single post pages. (See my question here and the answer by @gmazzap why you should rather avoid $post outside the loop) Now that you have the post parent ID, … Read more

Add a header before fields added with the attachment_fields_to_edit() filter

I’ve found out that you can use the tr attribute for creating entire rows: function my_attachment_fields_to_edit( $form_fields, $post ) { $form_fields[‘attachment-header’][‘tr’] = ‘ <tr> <td colspan=”2″> <h2>My title</h2> </td> </tr>’; $form_fields[‘attachment-url’] = array( ‘label’ => __( ‘URL’, ‘plugin’ ), ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_attachment_url’, true ) ); $form_fields[‘attachment-width’] = array( ‘label’ => … Read more

How can I save the original filename to the database?

How about saving the original filename inside the current $_REQUEST and processing it whenever WordPress generates the attachment metadata: /** * Store original attachment filename in the current $_REQUEST superglobal * * @param NULL * @param Array $file – Uploaded File Information * * @return NULL */ function wpse342438_store_attachment_filename( $null, $file ) { $_REQUEST[‘original_filename’] = … Read more

Hide “Gallery Settings” and “Insert into Post” button from Attachment window

If you actually wanted to remove it instead of just hiding it you could remove the ‘admin-gallery’ script that is used to insert the gallery settings form. And if you wanted it to be remove only for non-admins then something like this should work: function disable_wp_gallery() { if( !current_user_can(‘manage_options’) ) wp_deregister_script(‘admin-gallery’); } add_action(‘admin_enqueue_scripts’, ‘disable_wp_gallery’);

How to replace “wp-content/blogs.dir” with “media” for attachment permalinks?

Actually … the blogs.dir part isn’t used except for internally. Let’s say you have a network with two sites – http://url.com and http://sub.url.com. The files will be located in (respectively): http://url.com/files/2011/06/… http://sub.url.com/files/2011/06/… The blogs.dir directory is where the images exist physically, yes, but your .htaccess file is routing the virtual directories I just listed above … Read more

attachments with tags and get_posts

From this page in the codex, i see that this parameter requires an array so i’d try this way: $vidArgs = array( ‘tag__in’ => array(5), ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’=>’video/quicktime’, ‘posts_per_page’=>20 ); $videos = get_posts($vidArgs); foreach ($videos as $vid) { ///….

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)