Automatic image renaming based on title
Hook into the filter ‘sanitize_file_name’. See my plugin Germanix URL for a working example. A plugin doing this is Rename Media.
Hook into the filter ‘sanitize_file_name’. See my plugin Germanix URL for a working example. A plugin doing this is Rename Media.
You can do it via ajax, first, let’s change your current function to this: <?php $args = array( ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’, ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’, ‘post_status’ => null, ‘numberposts’ => -1, ); $images = get_posts( $args ); $imagenum=0; foreach($images as $image): $imagenum++; ?> <div style=”width:110px; float:left;”> <?php … Read more
When you just have raw image files, that you want to assign to a post, wp_insert_attachment will do the job. With attachments already present in your database you can use wp_update_post to set the attachment’s post_parent. Like this: wp_update_post( array( ‘ID’ => $attachment_id, ‘post_parent’ => $parent_post_id, )); To recieve a post’s attachments you can use … Read more
Use these: get_post_meta($attachment->ID, ‘_title_en’, true); get_post_meta($attachment->ID, ‘_description_en’, true); get_post_meta($attachment->ID, ‘_title_es’, true); get_post_meta($attachment->ID, ‘_description_es’, true); See if you need to use the _ prefix: Creating Custom Fields for Attachments in WordPress Also: Function Reference/get post meta
Because the credit data is saved in the attachment’s post meta, not the main post: $credit = get_post_meta( $post->ID /* Wrong ID! */, ‘credit’, true ); Instead you need to catch the ID of the inserted image: function attach_image_credit( $images ) { $return = $images[0]; // Get the image ID from the unique class added … Read more
OK I finally found the problem! I was trying to assign the same slug to both the attachment and the parent post, and apparently WordPress won’t have that. The “name” in the media library for the attachment was correct but the actual slug was getting a -2 at the end. Here’s the fixed code, simply … Read more
You can use ACF(Advance Custom Filed) for this please read document for this https://www.advancedcustomfields.com/
On the Trac ticket you’ve linked at the bottom there is a solution to make it work function _save_attachment_url($post, $attachment) { if ( isset($attachment[‘url’]) ) update_post_meta( $post[‘ID’], ‘_wp_attachment_url’, esc_url_raw($attachment[‘url’]) ); return $post; } add_filter(‘attachment_fields_to_save’, ‘_save_attachment_url’, 10, 2); function _replace_attachment_url($form_fields, $post) { if ( isset($form_fields[‘url’][‘html’]) ) { $url = get_post_meta( $post->ID, ‘_wp_attachment_url’, true ); if ( … Read more
you can use this snippet to get the first image of a post attachment id: $images =& get_children( ‘post_type=attachment&post_mime_type=image&post_parent=” . $postID ); $attachment_id = $images[0]->ID;
Good news for this old question, since WordPress 4.7, pdf’s thumbnail are automatically generated.