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
- Restrict custom post type to only site administrator role
- How to force one column layout on custom post type edit page?
- Search multiple custom fields by using meta_query
- Redirect after deleting post and keep track of pagination
- How to sort a table of custom posts by column containing custom field
- remove_action conditionally for Custom Post Type
- Assigning a role to a specific custom post type (and ignoring other post types)
- Display posts in random post types
- Archive filter disappears on no results?
- How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
- How to get Custom Post ID by adding filter to child theme’s function
- WordPress custom post type archive with description
- Remove All, Published and Trashed Post Views in Custom Post Type
- How to replace custom post type slug with an ACF value?
- Link users to a custom post type
- WordPress if in term*
- Weird problem happening with custom taxonmy when creating/updating posts
- CPT: if more than X images are in post, use pagination
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Validate custom fields before save using WordPress Rest API
- How can I dynamically add a post to a custom post type which uses a custom field?
- Conditional Query of Custom Post Type and custom taxonomy
- custom post type WYSIWG removes paragraphs when displayed
- ACF From & To Date Validations
- Structure of data : CPT + terms
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Default text in a specific post type, but not visible?
- How to remove post listing page for a custom post type
- How to include term custom meta into the custom taxonomy term permalink structure
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- How to update post meta on uploaded image from a custom form?
- Order post by date with ACF
- Ordering Submenu Pages in WP 3.1
- Querying & displaying custom post type into an existent page [closed]
- How to customize work area / admin area in a custom post type without plugins?
- Change “empty trash” button text?
- Move Genesis Single Page/Single Post Title
- Post loop count is not in order
- How to inherit field value from parent post into in child / sub post
- why post_class() function apply css classes to all other files?
- Custom post type’s posts are not showing anywere but in xml sitemap
- How to use single.php for creating, reading and editing Custom Posts with ACF
- Only show columns in custom post type?
- posttype and custom fields on multisite
- Display Custom Post Types Glossary
- Custom fields not showing in custom post type
- How should I structure complex content hierarchies?
- Convert Custom Table Data Based Plugin To Be Searchable
- Using WP meta query to show custom post types by a start and finish date
- Problems making shortcode with custom post types and taxonomy
- Advanced custom field – posted fields from custom post type
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- WP 3.1 custom post type permlinks
- Placing Admin Post Metaboxes in Tabs
- How to display author details in a custom post type in the wordpress backend?
- Show/hide posts and categories based on user meta
- ACF – Retrieve custom taxonomy from a relationship field
- Set up a WP Cron scheduled event to update calculated ACF field
- Why is my custom post content only viewable when signed into WordPress?
- Show Post Revisions on front-end
- How to show Custom Post Type – Case Study using Shortcode & ACF
- Add custom post related by custom field to custom post
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- Issue to display Permalink (ACF Relationships in Custom Post Type )
- Querying posts that don’t have a certain key value or don’t have the key
- Taxonomy shows up twice on Custom Post Type
- Create 3 Levels of relations with WordPress
- How to Disable option of meta field if that option is selected for any other post in custom post type?
- How to add custom supports for custom post types?
- Linking posts together with Advanced Custom Fields “both ways”
- Multiple WordPress Sites, Same Database but Filtered Content
- How can I save a Custom Post Title and Slug with a Custom Field?
- Custom Field as Custom Post type element class
- Extracting Post ID and passing through as an attribute in a shortcode
- Change Background Color For CPT Template
- How to query posts by meta keys AND under specific category?
- how to load custom single.php?
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Function that get ACF fields value before saving
- Problems with a custom meta_box
- Custom Post-type not returning the right child_of
- How to apply order on custom taxonomy and custom meta key on custom post type
- Register a title automatically with a relationship field
- How to make a template for a specific post of a custom post type?
- Bulk update custom post types
- ACF select box css color change
- Creating post custom field text area
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Delete old thumbnail when updating new
- Display ACF object field data using Elementor Custom Query
- Sort CPT by taxonomy AND THEN by custom field