Display one random image, but only if landscape

ok, following the comments: //from https://stackoverflow.com/questions/37537577/wordpress-query-by-attachment-meta-image-size add_filter(‘wp_generate_attachment_metadata’, ‘add_metac’, 10, 2); function add_metac($meta, $id){ update_post_meta($id, ‘height’, (int) $meta[‘height’]); update_post_meta($id, ‘width’, (int) $meta[‘width’]); update_post_meta($id, ‘ratio’, round ($meta[‘width’] / $meta[‘height’] , 2 )); return $meta; } at this point you will have, for the newly uploaded images, in the postmeta table all the information and a ratio >1 … Read more

Force all images to full size in page template

This code works, although I suspect that it could be more efficient – or replaced by a better filter. I modified this code from the answer to this question, which was the best choice out of all the googles I spent hours trying out.enter link description here You will need to change the ‘full’ to … Read more

WP Query search for attachments and their exact title

Try something like that The reverse of this: https://wordpress.stackexchange.com/a/209714/180599 <?php global $wpdb; //The reverse of this: https://wordpress.stackexchange.com/a/209714/180599 $supported_mimes = array( ‘image/jpeg’, ‘image/gif’, ‘image/png’, ‘image/bmp’, ‘image/tiff’, ‘image/x-icon’ ); $all_mimes = get_allowed_mime_types(); $accepted_mimes = array_diff($supported_mimes, $all_mimes); //and… $keyword = stripslashes($_REQUEST[‘keyword’]); //$search = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_title=”%s” OR post_content=”%s” “, $keyword, $keyword … Read more