500 internal error at wp_generate_attachment_metadata
You might need to require once this file: wp-admin/includes/image.php
You might need to require once this file: wp-admin/includes/image.php
I took a quick peek at the other question referenced in other comments, and the gist of how you loop through attachments there meshes with what is shown in the wp_get_attachment_image documentation example. In a nutshell, any attachments on a particular post will reference that post by ID. In particular, it’s crucial to understand that … Read more
If this is related to your other question then the custom field is attached to the post and not the attachment. You need to get the post ID of the post first then you can get the custom field. This should work. global $wp_query; $attachment_id = $wp_query->post->ID; $parent_id = get_post_field(‘post_parent’, $attachment_id); echo get_post_meta($parent_id, ‘my_custom_field’, true);
The Image added by Add Media is included in the Content.So I have splitted the image from the content.Below is the working code for my Question. <?php $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches); ?> <div class =”single-post-flex-slider”> <ul class=”slides”> <?php for($i =0;$i<$output;$i++){ ?> <li> <img src=”https://wordpress.stackexchange.com/questions/174038/<?php echo $matches[1][$i]; ?>” width=”500px” height=”300px” /></li> <?php } ?> </ul> … Read more
You’ve probably solved this, but for anyone else that needs this: $wp_taxonomies[‘category’]->update_count_callback = ‘_update_generic_term_count’; This is significant in the case of attachments. Because an attachment is a type of post, the default _update_post_term_count() will be used. However, this may be undesirable, because this will only count attachments that are actually attached to another post (like … Read more
Maybe you have an image that was smaller or equal to the thumbnail size, if so, then no thumbnail will be created, and this.data[i].sizes.thumbnail will be undefined.
So there are several ways images can be “related” to post: When you upload image in post context that post is set as its parent (that is parent field of image attachments post has post’s ID). When you set image as a featured on a post (or use similar functionality from custom fields frameworks) the … Read more
The WP_Query documentation on the codex specifically says: ‘attachment’ – an attachment. Whilst the default WP_Query post_status is ‘publish’, attachments have a default post_status of ‘inherit’. This means no attachments will be returned unless you also explicitly set post_status to ‘inherit’ or ‘any’. I am not sure why it was working before because this is … Read more
If you change the structure of the permalink, you have to provide the rewrite rules to understand the new structure. Also, you are not building the attachment permalink correctly. The next code is working: add_filter( ‘attachment_link’, ‘wpd_attachment_link’, 20, 2 ); function wpd_attachment_link( $link, $attachment_id ){ $attachment = get_post( $attachment_id ); // Only for attachments actually … Read more
You don’t get any ordering, because you are making multiple get_posts() calls and only retrieve a single post in each of them. You cannot order a single post. 🙂 You need to get rid of outermost loop and just pass a set of IDs (that would be your $instance[‘data’]) to retrieve via single get_posts() call.