Outboard Memory – Query Thumbnails & Crop Images CSS Trick
Two little tricks that came up this week . . .
Random Posts Must Have Featured Image Set
Sometimes you want to query a random set of posts but only return those with featured images . . . you can using ‘meta_key’ => ‘_thumbnail_id’ like so . . .
<?php $args = array( 'post_type' => 'project', 'posts_per_page' => 3, 'orderby' => 'rand', 'meta_key' => '_thumbnail_id', ); $the_query = new WP_Query( $args );
Handy. At least for me.
Now that I’ve got featured images, I usually have a variety of aspect ratios making uniform layouts a pain.
Enter object-fit and if you already knew of it I don’t know why you didn’t tell me. You can see the difference it makes in the two examples embedded below. Not earth shattering but really handy for stuff I do all the time.