I think you forgot to check if $the_query have posts.
<?php
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => 1,
'orderby' => 'rand'
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="testimonial push_2 grid_10 clearfix">
<blockquote>“<?php the_field( 'testimonial' ); ?>”</blockquote>
<cite>—<?php the_field( 'name' ); ?></cite>
</div>
<?php endwhile; else : ?>
<p>There were no testimonials :( </p>
<?php endif;
wp_reset_postdata(); ?>
And also don’t forget to reset postdata if you are running multiple queries on a page.
Related Posts:
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- wp_query to find posts by year and month
- WP_Query orderby modified to include custom meta changes
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- How do I list a custom field and custom taxonomies for each result in a loop?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- sorting in wp query based on custom field value
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Error in WP Query. If variable is empty it is displaying previous post value
- Display all posts in a custom post type, grouped by a custom taxonomy
- How to use a custom post type as front page?
- WP_Query orderby custom field then post_date in one query
- Sorting a query by custom field date
- Display several random posts, but make sure a condition is met
- How can I generate a RSS feed based on a custom WP_Query?
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Retrieving 3 latest post from each of 5 different custom post types
- Search Custom Post Type with all meta attached?
- How to sort CPT by custom meta value (date), and return posts month by month
- How to solve suspected memory issue in custom WordPress loop?
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- Display two post types ordered by two custom fields
- Get post info inside modal window?
- Get_post_meta() won’t return value
- Query Custom Post by Category
- Having trouble with custom date field for CPT query (WordPress)
- Display posts if a custom field value is equal to another custom field value
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Sort by two dates. Default entry date and custom field if present
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Display custom post on home page based on a metabox selection
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Conditional to modify query results
- get_template_part() – post-meta not working?
- Filtering by Post Meta Custom Fields – Performance
- WP Query—Relationship between two custom post types and their fields
- Create a random unique 6 digit number as custom field for custom post type
- How to insert content from another Custom Post type into Post?
- Get all Posts If has same custom field values in Posts
- WP_Query | ‘post_type’ doesn’t work
- Filter by custom taxonomy slug on a custom post type
- Can I create a loop with multiple post types and specify different $args for each post type?
- Calculate all custom field values in the post loop
- wp_query check if integer exists in custom field’s array
- Custom loop with multiple taxonomy queries
- What’s the WP way to load remaining custom posts?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Tag page only display 10 posts
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Display post from a date range from custom field
- post_per_page ignored in WP_Query
- Get Specific Template Part if Custom Field is Some Value
- Getting a custom post’s custom field based on another custom post’s custom field select
- WP_Query orderby not work with meta_key
- Custom Post type loop with ACF not displaying properly
- Trying to add a class to post links
- Display the current post in browser as the first post in a loop (for a slideshow)
- Display post from custom post type
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- WP query_posts group by meta field related
- posts_per_page in custom WP_Query does not override “Reading” settings?
- Custom Form / Search with Custom Post Type Data
- Create if else for post types in WP_Query ‘post__in’ values
- WP Query from two Custom Post type fields as statement
- Pagination Not Working When Used With WP_Query() `offset` Property
- How to avoid duplicate posts queried from custom meta?
- SEARCH QUERIES – REVERSE OUTPUT
- 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?
- post_type incorrect for custom post type
- Adding a Section for Visitors
- subtracting the current post form then whole loop, which is generating all CPT titles
- Mix Facebook and Twitter feed into custom posts
- Sort loop by custom field from different post type
- Strange behavior on WP_query
- WordPress loop, show only one post per custom field
- How To Loop Through list with Custom Post Types
- Custom Post Type + Category archive
- Calling specific page with wp query
- Loop with Custom Post Type and Taxonomies
- display news with pictures 3 small and one large (loop)
- Get result from Custom Field in Custom Post type
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- 404 on Pages for Custom Post Type & Query_Posts
- Custom post-type’s pagination not working in category.php
- Query Custom Post Type by Tag
- Show Posts in Vertical Tabs with Scrollbar
- How do I filter a custom post type loop by a field?
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end
- How to insert a post from a different post type after every nth post
- Sort CPT by taxonomy AND THEN by custom field
- Complex Custom Loop with Includes
- Query order by a numeric ACF field