You can use the fields parameter of WP_Query to get just IDs back, then iterate over them with a foreach loop:
$args = array(
'post_type' => 'services',
'posts_per_page' => -1,
'fields' => 'ids',
);
$query = new WP_Query( $args );
if( $query->have_posts() ){
foreach( $query->posts as $id ){
the_field( 'the_field', $id );
}
} else {
echo 'There are no services';
}
Related Posts:
- Filter by custom field in custom post type on admin page
- Filtering a WP_Query meta_query by numeric values isn’t working
- Populate a ACF Select Dropdown from Custom Post Type
- Filter a custom field based on selection of another custom field (ACF) [closed]
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Count custom post types with a specific meta value
- Change message given when deleting post from custom post type
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Display posts if a custom field value is equal to another custom field value
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Query Custom Post Types by date (custom field) range
- Remove duplicated values from a loop
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- “add_post_type_support” with Custom Post Type & ACF
- ACF simple text field value not showing
- Post Object Filter by Custom Field, not title (ACF)
- Custom Post type and Custom Field WP_Query
- Display multiple custom post types and sort them chronological by one of their fields
- Multiple ACF Repeaters within a Custom Post Type
- How to change post featured image using a custom field of category?
- Custom fields vs. Custom post types for a Portfolio Website
- How to add a post slug to a url?
- Add custom ID to CPT posts only create not update
- ACF Field on CPT Slug
- WP_Query order by custom field, then randomly order some of results
- Custom Post Type + ACF and performance [closed]
- Meta Query Not Returning Output Despite Having Matching Values
- How to render a custom post type template with custom fields using shortcode
- How to query WordPress posts bycustom field with a max characters’ length
- The loop seems stuck to a single (now deleted) post
- Multiple Frontend Filters Using Advanced Custom Fields
- Specific routing for CPT
- How To Import CPT With Only Few TEXT ACF Fields From Front End?
- Advanced custom field boolean value in custom post type
- Why would social icon badges disappear after adding a custom post type?
- ACF repeater field usage
- List of users that clicked a ‘Join’ button at single post
- set_query_params using custom params defined in functions file?
- Custome fields not displayed
- How to define the template for custom posts?
- Batch Extract Date from post title and put into ACF custom field
- Query entries from custom post type in an ACF flexible content field
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How to export custom post type with ACF to individual file with automation?
- Custom post types, disable fields
- ACF Relationship Posts how to show additional content
- Limit search field to just search a custom post type with custom fields
- Custom field with Types: get custom field’s value label (of type select)
- Show posts associated with ACF post object and custom post type
- How can i show ACF in post excerpts
- count & sum the value of custom field of the author post in dynamic posts
- Create if else for post types in WP_Query ‘post__in’ values
- Grouping custom wordpress post types by acf value
- Set Post Private if no linked Post Objects (ACF)
- Show in an entry a Custom Post Type associated to a post
- Display a Custom Post Type with Advanced Custom Fields on Homepage
- CPT email notification including only new value custom fields
- How to display posts with plugin (advanced custom fields) field groups?
- WordPress – display relationship between blog posts and custom posts
- Same custom post type with different ACF
- Load info from customposttype into template page
- Subpages URLs for Custom Post Type
- ACF meta_key and meta_value break loop
- search results to show individual ACF fields from inside custom posts
- Save_post acf data not updating category of post type
- Videos Post Type with Custom Filters
- Display Specific Posts at Start of Loop
- How to show link to product in custom fields?
- How to display custom post type pagination buttons when processing AJAX request
- Adding specific custom fields (images) to post excerpt
- filter using custom fields
- In the admin, how can you list thumbnails instead of titles for a custom post type?
- Use output of wp_dropdown_categories($args)
- CPT: execute code after load if parameter is set
- ACF Post Content Not Being Searched
- Values show up in custom home page but not in custom post pages
- Display related post content and custom field content
- WordPress page not showing up – replaced with last 10 posts?
- Fixed custom fields depending on posttype/category
- Showing custom post user wise with different color in wordpress
- Group/list/sort custom post type posts by date in tabs from acf datepicker field
- Grouping and paging CPT events by month with custom field date
- How to load custom post type plugin after acf options page (or get settings from there another way)?
- Advanced Custom Fields – Add Field to Specific Page [closed]
- $post breaking container loop
- Collection of fields in a single post
- using a template for more then 1 page
- Retrieve a post with its ACF repeater fields in wordpress
- How to I add count of custom posts listed in a post as a prefix to its title
- Filter page ID outside the loop and order
- Custom taxonomy meta fields
- Custom Sort Order for Custom Post Type Taxonomy
- Display custom post type attached media file sizes
- WordPress post objects in one parent post object
- Meta query with ACF relationship field
- Code output help please! WordPress> ACF > Relationship > Post Object
- How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?
- ACF Custom post type name changing issue