Something along these lines should work, not tested for syntax errors though
function random_post() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 1,
);
$post = query_posts( $args );
}
if(!$post->post_excerpt){
random_post();
}
// Then down here you would do whatever with the $post object
Related Posts:
- How to replecate the _fields parameter in custom REST api endpoint
- How to retrieve _embed (etc) fields in get_posts custom query?
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to use the_posts_navigation for wp_query and get_posts?
- WP_Query vs get_posts
- How to order by post_status?
- Using get_posts vs. WP_Query
- Delete all posts from WordPress except latest X posts
- Sanitation needed for WP_Query or get_posts calls?
- Differences Between WP_Query() and get_posts() for Querying Posts?
- get_posts with multiple categories
- get_template_part in for loop
- Use of caller_ get_ posts
- How-to exclude terms from the main query the most performant way?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- WP Rest API v2 return posts with specific tag
- Get posts by meta data OR title
- Meta Query with date and time on the same Day before given time
- Get posts with condition on comment meta value
- Function to check if author has posted within the last x days
- Use post__in and post__not_in together?
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- How to get post from all Blog Multisite to the Main Site?
- WP Query post meta value
- Get all posts without tags
- How to find out what “Blog pages show at most” is set to [duplicate]
- Trying to check and see if a post has a featured image outside of the main loop
- WP_query category__in not working, only pulls from first category
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- Order WP Query posts by custom order calculated from post meta values
- How do you Query posts with nothing in common?
- WP_Query, tax_query and term_meta: How to?
- Get posts for last working week in WP_Query
- How to find a post id using the post_excerpt?
- Get posts for which a custom field is not present, with get_posts
- get_posts() not working with multiple statuses
- WP_Query To call data from diffrent tables
- Help with WP_Query – Too many mySQL queries
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- add active class based on permalink and url
- $WP_Query: How to display excerpt on first post only
- Why does get_posts only show results for Admins or logged-out users?
- the_post() within switch_to_blog() altering my excerpt
- WP_Query post_parent parameter always returns children of current page
- get_post_meta slowing down my page load (in a plugin)
- How to count posts with specific arguments
- Check return value of get_posts
- Best choice for multiple loop in page?
- Get all posts which was posted on X Days WordPress
- Query post with meta value in set of values
- meta_query: check if number exists
- get_posts output always same post
- get_posts always returning the same number of posts = 5
- complex get_posts() query to select child pages
- Get user first name from custom endpoint
- JSON – Create rest api endpoint for Advanced Custom Fields
- Query_vars support in Rest API
- has_excerpt() not working inside wp_query
- get_posts custom field
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- How to apply a function to a metadata value before launch a WP Query?
- Posts query according to meta box date
- Woocommerce: order posts by meta key
- How to get posts by category and by choosing a taxonomy term?
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- get_posts query matches too many results
- Why is get_the_excerpt returning full content
- Search for pages with permalink
- How to query for a page, get data, then query for child pages of that page
- Execute PHP function inside the admin area
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- How can I return only IDs from the `posts` REST endpoint?
- How to search by slug and old slug in single API
- How to add date_query to meta_query array
- WP_Query retuning empty array in rest api
- get_posts query is taking about 40 seconds to execute
- Form checkbox value going to dynamic URL
- wc_get_products() return empty object
- How can I filter products by meta in Woocommerce REST API?
- Related posts queries
- How to get meta key list efficiently?
- how to get wp_query posts only first letter of alphabet A?
- custom excerpt is not being shown
- getting posts by tags
- I cannot get tax_query in get_posts() to work with custom taxonomy
- Getting the last X posts, but in ascending order of time
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Display posts from catagories
- When should you use WP_Query vs query_posts() vs get_posts()?
- Why WP_Query in functions.php is not working when get_posts works?
- Retrieve posts in custom post type and specific taxonomies
- Query specific number of posts for each post type in specific order
- tax_query not working properly with get_posts
- the_excerpt() not working in custom archive
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Custom Taxonomy in custom REST API search
- Sort by multiple columns using get_posts
- How to cache wordpress get_posts query using transients?