0

I am loading single images into a post and calling their source from my custom post type template single-photo.php :

src: "<?php echo get_post_meta($post->ID, 'single_photo', true); ?>"

I want to pull an image from a random post only from that post type [PHOTO]. I know the url will be mysite.com/photo/-random-photo-, how could I grab a radom meta field?

0

You could pull it directly form the database:

global $wpdb;

$random_photo = $wpdb->get_var("SELECT meta_value FROM wp_postmeta WHERE meta_key like 'single_photo' ORDER BY RAND()");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.