Show custom field on attachment page?

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

Get images from the post

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

Change categories count to include media attachments

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

Creating attachments archive in tags and categories

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

Change permalink to attachment

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

get_post orderby not working in plugin

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.

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