How would I pull a single random image from custom post type “athletes” and the custom image field “athletethumbnail” to be displayed in my sidebar? (I have PHP enabled for my text widget on sidebar.)
Leave a Reply
You must be logged in to post a comment.
If I get your question right, as you mention Tag in the title, but not in the Content – and also mention a random image but then it’s not a library image but a custom field value…
So, the following code will grab 1 random custom post type that has a custom field value that’s not empty. And it’s a mix of
get_posts
,get_post_meta
andCustom_Field_Parameters
: