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
- Display Posts that fit a certain criteria on Category pages
- How to display custom field in product description?
- Sort custom post column by generated value?
- Custom Column in CPT admin table not updated after Quick Edit save
- How to only display all posts to a custom User Role?
- Why this didn’t work if i use get_the_ID(), but works if i pass the numeric id
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- How to keep custom post type related information
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- when looping through custom post data not appearing
- How to avoid duplicate posts queried from custom meta?
- Custom Metabox Info Not Saving
- Add custom template ‘sub-page’ to Custom Post type?
- How can I query and sort custom-post type using WP_Query
- Meta query and compare “!=” not working as expected
- custom post types, custom fields and normalization
- Display Custom Field or Custom Taxonomy in front page /post/product
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- Orderby if between two meta fields
- How to add dynamic fields on wordpress custom post type page in admin section
- How to access repeater field of a custom field?
- Filter posts by their related field’s custom field
- Post Click Redirect to Custom URL instead of Single Post Page
- wp_insert_post deleting previous post custom meta
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- Show posts from WP Custom Post Type selected from a field in a metabox
- Problem in moving cpt’s from local website to live website
- Custom Page Template – Widgets of wrong sidebar
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- Is there a way to create a sidebar of bullets
- register_rest_field update_callback don’t work for $_FILES
- Query custom post type and custom field by URL parameters
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Where is get_post_meta value located?
- How to convert Post Object Custom Field into Tags
- How do I query with multiple custom fields orderby in same column?
- PHP Warning with Custom Fields
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- I want to create a metabox under custom taxonomy
- meta query multiple values for the same key
- Problem with multi checkboxes value in metabox?
- How can I register multiple custom post fields to json?
- Disable Sidebar on certain pages
- Sort custom post archives by a meta value from a different custom post type?
- filter using custom fields
- Show Post columns to specific users on condition
- Displaying Custom Fields from Custom Post Types [closed]
- Displaying posts inside table having issues
- Custom post types – meta_query: search lesson which starts sooner
- Sql Update CPT from publish to draft and particular custom field
- Custom post types & Pages hierarchy – Error 404
- Ordering Post by Meta Key (Not Working)
- Post Filtered by Custom Field Value
- Adding a Section for Visitors
- Error when moving custom post type to bin
- Automatic Set Category For A Custom Post Type
- How to Disable option of meta field if that option is selected for any other post in custom post type?
- How to link custom field of two custom post types?
- How to replicate data storage and querying using WordPress. Custom posts/fields or Custom db tables?
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- CPT – Custom Text fields point to new url permalinks
- Autofill advanced custom field with user data
- Confused about where to store my data
- Widget area for individual posts (custom post type)?
- Advanced search form with multiple custom fields
- filter rest api post by a acf filed
- Query posts by multiple custom fields
- How to prepend text to custom field value A, but only if custom field value B matches a certain string?
- Enforce all custom posts have specific custom fields
- Simple Data picker meta box
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- sorting in wp query based on custom field value
- Use WP Title instead of custom field to call
- PHP Notice: Unidentified index
- Custom taxonomy template for custom fields loop [closed]
- Meta_Query refuses to return results
- Sort loop by custom field from different post type
- Custom Fields with add_post_meta()
- Run query on specific admin options page and send results to select field in another function
- get_previous_post_link and get_next_post_link of custom post type that share custom field value
- Meta_query by date for Events archive
- Multi Photo Upload with Caption on Front End for Custom Post Type
- Custom post type that lets users create a set of posts?
- Add more custom fields when creating a new custom post type
- Search facility with directories
- check_admin_referer not working in custom meta box for custom post type
- Create Inclusions and exclusions
- How do I display specific custom posts, and how do I edit a post’s singular page?
- WP_posts (Not meta) extra custom field column show and change it in a custom post type