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
- Is it possible to use the_post 2 times in one loop
- Multiple post in One Loop in wordpress
- SEARCH QUERIES – REVERSE OUTPUT
- Template with ACF and Pagebuilder
- Order by meta_key field in WordPress not meta_value field value
- a WordPress connected to 2 database
- “read more” redirects to the wrong page
- Diffrent layout for posts [duplicate]
- How to display particular set of wordpress post on a webpage?
- How to show post views shortcode data for each post on Posts List Page?
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- query posts with selected post ids first
- Change URL of previous posts and next posts link in WordPress
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- How to create page with post content in it?
- Count singular post views automatically
- Create/Set Category as Title of Post
- How to distinguish pages created by woocommerce?
- Order posts inside bootstrap card columns
- Moved a website and excerpts don’t work for old posts
- How to remove a post from results by ID after query?
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Mix post date with post meta value using WP_Query
- Please I want to prefix my WP posts title according to each category
- Change post value in WordPress
- How to use two query result together in one loop
- Add id attribute to h1 element of wordpress post
- subtracting the current post form then whole loop, which is generating all CPT titles
- How can I get the last post while on the first post for pagination? As if it were infinite
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- WP_Query that targets all categories
- Counting Posts by Category