Skip posts without a thumbnail in loop

You can try to add ‘meta_key’ => ‘_thumbnail_id’, to your input arguments: $args = array( ‘numberposts’ => 5, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘_thumbnail_id’, ); to query only posts with thumbnails (i.e. featured images). ps: instead of this structure: if ( !has_post_thumbnail() ) { continue; } … Read more

Multiple featured image thumbnails for post types (Multiple Post Thumbnails plugin)

Dude, you’re doing this the hard way. You can do what you want totally with a single ‘featured post thumbnail’. Read the documentation about thumbnail sizes in themes. You can inject custom thumbnail sizes in your themes funcitons.php and then give them as a parameter to the (get_)the_post_thumbnail() function. Please just read the documentation at … Read more

Re-order media links?

Edit: Added example of outputting the attachment’s id. Assigned it to the variable $attachment_id, since that’s how the core code refers to it. Note that the $post object (for the attachment) is passed into the callback of the attachment_fields_to_edit filter, so you’ll have access to all of the attachment’s properties. Yes, this can be done … Read more

Showing a placeholder/default img, if no featured image is set

Misspelling of thumbnail (thumnail) in the if statement. Also get_the_post_thumbnail does echo the thumbnail, but just returns the html. You need to echo it. Also, for checking if a post has a thumbnail, you can use has_post_thumbnail. if ( has_post_thumbnail($r->ID)) { echo get_the_post_thumbnail($r->ID, array(50,50)); }else{ echo ‘<img src=”https://wordpress.stackexchange.com/questions/44208/image_url”/>’; }

How do I add the featured image to the_content after the first paragraph?

You can do this using the ‘the_content’ filter: add_filter( ‘the_content’, ‘insert_featured_image’, 20 ); function insert_featured_image( $content ) { $content = preg_replace( “/<\/p>/”, “</p>” . get_the_post_thumbnail($post->ID, ‘post-single’), $content, 1 ); return $content; } Of course, you can add options to the the_post_thumbnail() function to define which size of thumbnail you’d like to use, etc… http://codex.wordpress.org/Function_Reference/the_post_thumbnail

Retrieve featured image as object

First get the registered image sizes and the featured image attachment id: $sizes = get_intermediate_image_sizes(); $post_thumbnail_id = get_post_thumbnail_id(); Loop through the registered sizes and create an array: $images = array(); foreach ( $sizes as $size ) { $images[] = wp_get_attachment_image_src( $post_thumbnail_id, $size ); } Combined as a function to place inside functions.php: function get_all_image_sizes($attachment_id = … Read more

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