You have two options. Either use get_field
or the_field
. get_field
just reads out the field from the db without and screenoutput. like you did in your first line:
$fields = get_field('testimonial');
the_field
instead is get_field
with an implied echo.
<?php the_field('testimonial'); ?>
so basically the_field would be enough. Aside you have to write a wp_query before and aside i would go with if and while instead of foreach. Like e.g.
$args = array(
'post_type' => 'testimonials'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_field('testimonial'); ?>
<?php endwhile;
wp_reset_postdata();
else: ?>
<p>Error</p>
<?php endif; ?>
(you would have to refine the query args but basically it would do the trick)
Related Posts:
- How to export custom post type with ACF to individual file with automation?
- Custom Post Type and Structure Question
- Adding specific custom fields (images) to post excerpt
- In the admin, how can you list thumbnails instead of titles for a custom post type?
- save_post affect creation and deletion
- Collection of fields in a single post
- Custom post type adding additional markup
- A question on creating filters for custom posts using taxonomy
- Conditional Query of Custom Post Type and custom taxonomy
- will post_id ever change? Can I safely use post_id for custom queries?
- List custom taxonomy specific to one custom post type
- Define new user capability for custom post types?
- How to allow visitors to enter custom post type?
- Is it possible to create relational metabox values in a custom post?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- Meta query for custom post type ignored in main query
- How to add a post slug to a url?
- Add custom ID to CPT posts only create not update
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- WP_Query to select custom post type with Advanced Custom Fields (ACF) date
- 2 Templates 1 custom post type according url
- How do I move/order posts with a tag to the end?
- changing meta value and meta key of price field
- Bulk Update Custom Fields for Custom Post Types
- ACF Field on CPT Slug
- WordPress sort search results by custom order
- WP_Query order by custom field, then randomly order some of results
- Cluster CPT posts to users based on ACF value from their profile on dashboard
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- ACF Values Don’t Show After Import Unless I Edit/Update Post
- Hide parent categories when clicked, and show it’s childs
- Custom Path/Folder behind a custom post type
- Time based access control of custom post types – what is good approach?
- Troubles with acf/save_post and WP_Query
- Query custom post type with ACF Date
- custom post type WYSIWG removes paragraphs when displayed
- Stuck in Order by more then one
- Custom Post Type + ACF and performance [closed]
- Show titles, date of all posts on single category page
- Meta Query Not Returning Output Despite Having Matching Values
- delete_published_posts does not work
- How to start a new post with custom Taxonomies already set?
- ACF From & To Date Validations
- WooCommerce sort products by the actual product width(not the shipping width)
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Create a custom php page and load it at a specific slug
- Structure of data : CPT + terms
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- How to handle paged param in post and custom-post-type?
- CPT archive admin menu label
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Default text in a specific post type, but not visible?
- Update postmeta Parent when post_status child change
- Order Custom Post Type by Custom Field Value
- WP_Query custom post type query not showing the exact post type
- Retrieve custom field from Contact Form 7 [closed]
- Shortcode to display Staff post type based on Location post type and Specialty post type
- Query Custom Post Type Taxonomy term with multiple parameters
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to query WordPress posts bycustom field with a max characters’ length
- How to remove post listing page for a custom post type
- How to include term custom meta into the custom taxonomy term permalink structure
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- A form that can save/edit after first input
- The loop seems stuck to a single (now deleted) post
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Adding the_content() in custom template email
- Cannot save CPT meta box
- non-hierarchical post type with hierarchical url structure
- Send notification to the admin when new custom post is submitted
- How do i search authors from search form using author’s name
- Allow users to create posts without logging in?
- How to update post meta on uploaded image from a custom form?
- How to add attributes to taxonomies that may be different from post to post?
- Pages are not saving due to custom post type
- How to group posts and get a mixed posts and groups view?
- Custom Post Types vs. Advanced Custom Fields (with Repeater Field add-on)
- Multiple Frontend Filters Using Advanced Custom Fields
- Migrating a taxonomy’s tags to the native category
- Integrate Custom Post Type Events into Calendar
- Specific routing for CPT
- Order post by date with ACF
- Displaying custom field according to date
- How to produce a sub-page-system in WordPress
- Best structure / rewrite rules to achieve the following url
- don’t publish custom post type post if a meta data field isn’t valid
- How does order=asc effect a wp_query (its acting pretty weird in a loop)
- How to set the seo title tag on a page by page basis?
- WebP Fallback for Inline Background Image in Style Attribute
- Adavnced custom fields relationship query plus query inside
- Query based on custom fields start and end date
- How to sort posts in a custom post type by title in ascending order by default?
- Redirect to another page using contact form 7? [closed]
- How To Import CPT With Only Few TEXT ACF Fields From Front End?
- Categorise Custom Post Types
- Advanced custom field boolean value in custom post type
- Why is my WP Query not returning first result’s post meta?
- Detect inside a custom query the kind of post type to assign custom classes
- custom post type vs. conditionally displaying meta boxes for specific terms?