Import Attachments – not attaching to post_parent

I think that importing attachments separately (which is not possible with native export) is precisely cause for your issue. Importer plugin has following code: if ( $post_parent ) { // if we already know the parent, map it to the new local ID if ( isset( $this->processed_posts[$post_parent] ) ) { $post_parent = $this->processed_posts[$post_parent]; // otherwise … Read more

Add an attribute to attachments

This can be done with two filters, attachment_fields_to_edit and attachment_fields_to_save, which do exactly what their names suggest. Let’s say you wan to add a source field. First, generate the field and fill it with its current value if that exists: function wpse133608_add_attachment_location_field( $form_fields, $post ) { $field_value = get_post_meta( $post->ID, ‘source’, true ); $form_fields[‘source’] = … Read more

Custom Gallery HTML only working when images are attached to post/page

You’re not passing your attribute array to the shortcode_atts method. You’re passing in an uninitialized variable. Your function starts with function get_my_gallery_content ( $atts ) { But then you don’t reference $atts again. The code is reading $attr, which is empty. Change the line ), $attr, ‘gallery’)); to ), $atts, ‘gallery’)); You also need to … Read more

Display attachment resolution size

The wp_get_attachment_img_src( $attachment_id ) function returns an array consisting of: The URL to the img width height To get the actual attachment/thumbnail/featured image ID, you want to use $att_ID = get_post_thumbnail_id( get_the_ID() ); in the loop. Outside the loop, you would have to get the Post ID somehow to feed it in as get_the_ID() refers … Read more

Show post tags on attachment page?

This should work to get the parent’s tags. <?php global $wp_query; $attachment_id = $wp_query->post->ID; $parent_id = get_post_field(‘post_parent’, $attachment_id); $parent_tags = wp_get_post_tags($parent_id); $tag_count = count($parent_tags); // Counting the tags to find know the last one so there is no pipe $i = 1; // Setting up the count if ($parent_tags) { ?> <div> Tagged with:<br /> … Read more

delete image attachments of a custom post type except featured image

Try this on for size: add_action(‘save_post’, function($post_id, $post, $update){ if ( $post->post_type === ‘newcomer’ && $post->post_status === ‘publish’ ) { $attachments = get_attached_media( ‘image’, $post->ID ); $featured_id = get_post_thumbnail_id(); //unset the featured image by ID if it exists unset($attachments[$featured_id]); foreach ( $attachments as $attachment ) { wp_delete_attachment( $attachment->ID, false ); } } }, 10, 3); … Read more

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