How do I link an image to the post it is attached to?

After some additional searching I was able to come across a function to generate the attachment ID here: http://pippinsplugins.com/retrieve-attachment-id-from-image-url/: // retrieves the attachment ID from the file URL function pippin_get_image_id($image_url) { global $wpdb; $prefix = $wpdb->prefix; $attachment = $wpdb->get_col($wpdb->prepare(“SELECT ID FROM ” . $prefix . “posts” . ” WHERE guid='” . $image_url . “‘;”)); return … Read more

How do i save and retrieve custom attachment meta?

The field id has to match in both function so if your field id is foo the when you save you need to look for that id and when you save a checkbox field its smart to remove it if not set so: function image_attachment_fields_to_save($post, $attachment) { if( isset($attachment[‘foo’]) ){ update_post_meta($post[‘ID’], ‘foo’, $attachment[‘foo’]); }else{ delete_post_meta($post[‘ID’], … Read more

How to protect post attachments related to a custom post type, from non-logged in users, on 1 subsite of a multisite installation?

Andrew, In the case where your custom post type exists on only one sub-site of your Multi Site installation, you can in your template file in which controls the display and output of your custom post type work with simple conditional functions such as; is_singular(‘post_type_name’); is_user_logged_in(); …and in-fact it might well be as simple as; … Read more

Set attachment tags from attachment’s custom field data

I managed to make it work but not fully. First, the code you provided is not retrieving an already saved post_meta. I based my code in the introductory code of this tutorial: http://wpengineer.com/2076/add-custom-field-attachment-in-wordpress/ And am using the regular post_tag taxonomy instead of a custom one. And, lastly, there’s a bug, after you close the Media … Read more

Where does the gallery shortcode gets its attachments from?

This completely depends on how your gallery shortcode looks like. If you replaced it with something custom, then you’ll have to take a look at the plugin (or the theme). The default gallery shortcode gets it from a query: $query_args = array( ‘post_status’ => ‘inherit’ ,’post_type’ => ‘attachment’ ,’post_mime_type’ => ‘image’ ,’order’ => $order ,’orderby’ … Read more

Getting the ID of any image for use in functions.php

Hopefully this helps, function mat_image_credit() { global $post; $args = array( ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ); $imgs = get_posts($args); foreach ($imgs as $img) { $field1 = slt_cf_field_value(‘flickr_credit’, ‘attachment’, $img->ID); $field2 = slt_cf_field_value(‘custom_credit’, ‘attachment’, $img->ID); if (!empty ( $field1 ) ) { echo ‘Image by ‘ . $field1; … Read more

WordPress Image Attachment using remote image

You’ll want to get very familiar with wp_insert_attachment(), download_url() and media_handle_sideload(). It’s a bit lengthy to get into the details here, but it absolutely can be done. I used these methods to create a media tab that allows a user to put in a vimeo/youtube URL which I store in a postmeta and use their … Read more

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