If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/
Check if value exists
This example shows how to check if a value exists for a field.
$value = get_field( 'text_field' );
if ( $value ) {
echo $value;
} else {
echo 'empty';
}
So, in for your case you would need to use:
<?php
$short_testimonial = get_field( 'short_testimonial' );
if ( $short_testimonial ) {
echo $short_testimonial;
} else {
the_title();
}
?>
Also, you should note, as others have mentioned, that you don’t need to echo the_title()
as it echoes itself…
Related Posts:
- How to display post list in a table layout (multiple queries in single loop)
- Should we trust the post globals?
- Get first post from wp_query
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Reverse chronology of post listing
- WordPress Number of Posts Not Changing With posts_per_page
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Specific loop in Shortcode
- Search widget breaks when using multiple loops?
- Converting multiple loops into one single loop with pagination
- Display posts with comments closed, with pagination?
- Group posts by year in loop
- How would I get 1 latest post from a query for 5 posts?
- Loop through all product posts?
- WP Query – duplicated posts once including tags in search results
- Display post from current category and same tag?
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- WP Query – Posts Per Page not working in combination with category__in
- Pausing and Resuming WP_Query results
- How to : pagination in 3 different custom loops on the same page
- List authors with the last post title and order by last post date
- wp_query random post
- Possible to alternate between two loops
- Loop doesn’t show title of second post and posts thereafter
- How to get posts published on the latest date?
- How can I remove the first two words and shorten get_the_title()
- Page and post loop same template
- ACF to select posts not displaying on blog page
- Getting blog pagination to work on page set as front page
- Display current post position in Elementor Posts widget
- Why in my query is display two title?
- WP_Query: Show 10 posts in date order, first three random
- WordPress Loop: How to display recent posts in multiple divs
- Not all posts showing in query
- how to handle the loop using filling bootstrap grid structure?
- WP_Query custom field pass the post id
- Custom WP_Query not working correctly
- WP_Query of Category Not Showing First Post
- If custom field is empty, use one from a previous post
- Display 3 posts with different HTML markup using a loop
- ACF flexible content block not showing on live site (works locally)
- While loop in functions.php outputting the_title() of each post on frontpage
- Display specific posts based on an ID of another post
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- long-title posts do not want published
- show loop id post , only first id can read
- Double loop output
- Loop through all posts showing duplicates
- Wp_query loop is not working as it should
- WordPress Request Post All Post ID in a Loop? [closed]
- WordPress loop uses unmodified posts array, why?
- Advanced Post Display/Pagination/Ordering
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- How to show the posts list into a static page? Problems to use the loop into a static page
- Adding a category at even positions on main loop with modified pagination
- Make assigning post to a specific category equivalent to assigning it to all categories
- Is there a way to separate wordpress titles from their posts?
- First post in loop displays twice
- posts_per_page – Repeats only first posts ‘post__in’ array
- Custom post order returning posts from other categories
- Print Current Post Index number within Loop
- Random sort within an already sorted query
- Search by Hyphen
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- Get title of post without using the_title();
- Find most recent authors
- Exclude posts with specific meta_value while sorting by a separate meta_value
- get_post_custom stripping styling issue
- Fetch posts from current week (Sunday to Saturday)
- Exclude posts with empty post_content in wp_query
- Exclude posts from featuring
- Lazy Load using WP_Query pagination
- AJAX filter posts by year
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Any number in meta key (wp query)
- is there a way to show the the post title after the image?
- Select only post id and meta value with WP_Query
- sql select for post_title and a term name
- Get the amount of posts on a current page
- Related Posts function not working
- How to display posts on custom page without declaring a posts page in reading settings?
- Why sorting posts doesn’t work properly?
- the wp_post_update isn’t working all the time
- Post title not displaying as recorded in the wp_posts table
- Moved a website and excerpts don’t work for old posts
- WP_Query sort by meta_value_num or date
- How to get all posts in gallery post format template
- Post gallery as carousel
- Showing content from WordPress ruins page CSS using WP_Query, without, content does not show
- Display Post by menu order
- Getting rid of the blog page entirely
- Custom Post Title as search term
- List posts related to category on a div [closed]
- query_posts different amount of posts per page [duplicate]