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
and Custom_Field_Parameters
:
$args = array(
'numberposts' => 1,
'orderby' => 'rand',
'post_type' => 'athletes',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'athletethumbnail',
'value' => '',
'compare' => '!=' /* will not grab posts with empty Custom Field */
)
)
);
$show_albums = get_posts ( $args );
echo get_post_meta($show_albums[0]->ID,'athletethumbnail',true);
Related Posts:
- Custom Post Type Data in Sidebar widgets?
- Including Custom Post Types in “Recent Posts” Widget
- Custom page sidebar using Template dropdown box
- How to exclude categories from a sidebar with active widgets in it?
- Replace Content of Sidebar on Custom Post Type
- How do I get the posts from single page custom post type from a sidebar to display in a page?
- Displaying database table in backend of wordpress
- Filter CPT based on meta box value using Flexible Posts widget?
- What method should I use for a sidebar widget that reads latest posts?
- Radom post image/link based on custom taxonomy
- How do I set the default admin sort order for a custom post type to a custom column?
- How can I change the admin search posts fields?
- Development of a WordPress Search Plugin – Best Practices
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- WordPress 4.4+ : How to revision CPT + metadata
- WP_Query orderby custom field then post_date in one query
- Using Custom Fields in Custom Post Type URL
- Adding meta values to permalink
- Filter a custom field based on selection of another custom field (ACF) [closed]
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- Custom field being erased after autosave
- How to select one major category (or custom taxonomy) for a custom post type?
- front end radio custom taxonomy with custom post type
- How to get source of custom meta image?
- Get post info inside modal window?
- Displaying Meta Box Image
- Display posts if a custom field value is equal to another custom field value
- Custom field default value with counter
- How to use custom fields to enable sticky posts on custom post types?
- Custom meta fields for specific custom type only
- Custom Fields vs Separate Table
- Check if a specific custom field exists?
- WordPress Create Post from front-end
- How to insert content from another Custom Post type into Post?
- Display custom post data in sidebar w/ dropdown
- Using several custom fields as custom post title
- Display custom fields on post excerpt or teaser
- How to create Blog Post Specific Widget
- Calculate all custom field values in the post loop
- add custom field to custom post type
- Role scoping for contributors down to the field level
- How to stick custom post at the top in search results
- WP_Query order by custom field, then randomly order some of results
- Callback to custom field is not working in WordPress REST API
- Cannot save CPT meta box
- custom comments form for custom post type
- Want to be able to sign up subscribers as authors
- the_post_thumbnail call removing li in code
- Custom post type’s extra fields – how to handle?
- Submitting Custom Post Types with custom fields from Front-end form
- post_per_page ignored in WP_Query
- finding and using post type fields in WordPress
- How to get dropdown instance value in WordPress custom Widget
- Sort custom post type by most current date picker
- Should Custom post types and fields be in the theme files or in a custom plugin packed into the theme?
- Custom sidebar for custom post type
- Remove default WYSIWYG editor without removing custom fields editors
- Methods for development wordpress themes [closed]
- Display custom meta on page that has been check in custom post type
- How do I update_post_meta() or add_post_meta() with an AJAX call
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Filtering Custom Post Type by Comparing Date and Two Meta Keys
- Automatically add a character to field in edit post page
- Change Post Meta via AJAX from the posts list table
- How to keep a record of changes to a custom field?
- Making a form for user to add new custom post with custom taxonomies and custom fields
- Saving metabox keys and storing values as array
- Mandatory field in Custom post
- Update value inside array update_post_meta
- WP query_posts group by meta field related
- How to store the third party script with HTML code in the wordpress custom input field?
- How To Read Read Custom Post Type Data in Headless CMS Mode
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- How to upload an image to a custom post type
- How to display custom field in product description?
- Add custom template ‘sub-page’ to Custom Post type?
- Is there a way to create a sidebar of bullets
- Where is get_post_meta value located?
- Automatic Set Category For A Custom Post Type
- Confused about where to store my data
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- WordPress loop, show only one post per custom field
- one get_posts to return a number of custom posts for each meta value
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Custom Post Type as invoice or order template
- How to use get_sidebar in plugin folder?
- Get result from Custom Field in Custom Post type
- Make each Value of custom field show related posts when clicked
- Advanced search form with filters for custom taxonomies and custom fields
- Filter Custom post type by another Custom post type
- How to display custom message for (Genesis) featured posts if no posts
- How to get lowest price from custom fields of posts
- Retrieve a post with its ACF repeater fields in wordpress
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Display ACF object field data using Elementor Custom Query
- Sortable admin columns ordering from custom fields isn’t combine com search and Dropdown filter
- WordPress custom field sorting, weird behavior: the latest post is at the end
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes