Confused with attachment mimetype order

Yes, this does seem like a lapse in template hierarchy. The easiest for case described would probably be handling logic in image.php, along the lines of (see get_attachment_template() for mime type retrieval): if( ‘gif’ === $subtype ) { include ‘gif.php’; } else { // generic image template } For more complicated logic it might be … Read more

How can I change wordpress attachment url and protect it?

I’ve figured out a solution, here is my answer 1, we can’t modify WordPress original data input, but we can modify and rewrite the output. So we can use the_content,wp_get_attachment_url to change this. add this code snippets into your plugins if (function_exists(‘add_filter’)) { add_filter(‘the_content’, array($scplugin, ‘AttachmentRewrite’), 10, 1); add_filter(‘wp_get_attachment_url’, array($scplugin, ‘AttachmentUrlRewrite’), 10, 1); } the … 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

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’);

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) { ///….

How to create a CSV on the fly and send as an attachment using wp_mail?

That’s because wp_mail expects the attachment to be a filename (filepath) that it can attach and send. You are supplying a string containing the contents of the file: function create_csv() { $filepath=”/path/to/the/file.csv”; $fd = fopen($filepath, ‘w’); if($fd === FALSE) { die(‘Failed to open temporary file’); } $records = array( array(‘dummy’, ‘data’, ‘found’, ‘here’) ); fputcsv($fd, … Read more

How to count media attachments?

Use this code if you’re in the loop: $attachments = get_children( array( ‘post_parent’ => $post->ID ) ); $count = count( $attachments ); If you’re not in the loop, substitute $post->ID with the ID of the specific post. But that should count all attachments.

the_content() behavior on attachment.php versus single.php

This is correct behavior, if your attachment doesn’t actually have anything in post_content field (which is quite common). When post–centric templates run, prepend_attachment() is used as filter to “emulate” post content. This is not the case with template “intended” for attachments. If you look at template-loader.php: elseif ( is_attachment() && $template = get_attachment_template() ) : … Read more

wp_insert_post featured image from library

You can use the function set_post_thubmnail(). After you inserted your post, just call this one, and you are ready to go. $yourpostid = wp_insert_post( $args ); // Define the post in the args first set_post_thumbnail( $yourpostid, $thumbnail_id ); // set the ID of your thumbnail to be the featured image of your newly created post.

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