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
- how do i remove posts from a WP_Query so the pagination is right?
- Very Slow Page – How to Optimize # of Queries?
- get_template_part and template file names
- Can I create a loop with multiple post types and specify different $args for each post type?
- Display CPT posts based on specific taxonomy
- WP_Query: include custom post type only with specific meta value
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- How to make sure content doesn’t display if selection is empty
- Show one item per category of a custom post type
- Meta Key Value in current-user-only loop
- 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 is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- How can I get the number of custom post type posts that have a specific attachment image set?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Including metaboxes from custom post types in global search — continued
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- Get Posts by multiple custom fields is not working
- WP Query with categories only shows one post and ignores the category
- Order Custom Post Type by Custom Field Value
- Problem: wp_query outputs all images on site
- First custom field value (out of several) displayed twice after query
- Possible to filter custom post type with multiple meta data?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- 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
- Custon Content within WordPress Loop
- Loop increase number
- WP Query ‘posts_per_page’
- Using wp_query to modify the loop in index.php for a CPT
- Display post from a date range from custom field
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- post_per_page ignored in WP_Query
- Get Specific Template Part if Custom Field is Some Value
- How to get specific post meta by title or id
- get_pagination not working on a custom post type query (using WP_Query)
- WP_Query with custom post type ID
- Getting a custom post’s custom field based on another custom post’s custom field select
- How to conditionally add Custom Post Type to Front Page
- hide specific div on single.php [closed]
- WP_Query orderby not work with meta_key
- Pagination not working on custom query on a page
- How do you output an unknown number of images in a custom post type with desired markup?
- Get data from PHP to JavaScript to set position of each post on front page
- display posts of custom post type with custom taxonomy
- Display custom post type for specific user
- Get post content from another section in custom single page
- Custom Post type loop with ACF not displaying properly
- Trying to add a class to post links
- postsperpage value not being applied
- Group by custom field value (start and end times)
- Display the current post in browser as the first post in a loop (for a slideshow)
- Display post from custom post type
- List all Custom Post Type posts excluding certain Taxnomy term
- foreach loop inside the loop creating duplicates in output
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Displaying information from custom field on custom post type
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Cache issue with WP_Query and custom field filtering
- Get post-meta value of all custom-posts – lowest to highest year-count?
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Custom PT, Taxonomys and wordpress query
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- How can i loop through custom post type according to custom meta field?
- Custom Post Type Query W/Category Dropdown
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Custom post type pagination error
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- What is the most efficient way to execute recursive complex queries?
- On click some element i want to use some template
- WP query_posts group by meta field related
- Page that lists publications by classifying them by taxonomy
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)