This comes directly from the ACF documentation:
/*
* Order Posts based on Date Picker value
* this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
*/
$posts = get_posts(array(
'meta_key' => 'custom_order', // name of custom field
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
if( $posts )
{
foreach( $posts as $post )
{
setup_postdata( $post );
// ...
}
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
}
Related Posts:
- Query current and future events, ordered by begin date
- Using WP meta query to show custom post types by a start and finish date
- Get month and day from a Date Picker custom field
- ACF Field to set Publish Date – Post Duplication upon Update
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- Recoverable Fatal Error – Object of class WP_Post could not be converted to string
- Querying & displaying custom post type into an existent page [closed]
- How to get a custom type post data when it has a connection with another custom type post?
- Custom post type showing same Post on all Pages
- Why would social icon badges disappear after adding a custom post type?
- Sort a custom post with ACF: Date Picker & Display Featured!
- ACF repeater field usage
- List of users that clicked a ‘Join’ button at single post
- Post loop count is not in order
- How to inherit field value from parent post into in child / sub post
- How can I add a shortcode to query Custom Post Type with ACF in WordPress?
- Custom Post Type page sorts differently on different environments
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- set_query_params using custom params defined in functions file?
- Custome fields not displayed
- Sort custom post type by most current date picker
- I am trying to get cutom post cout by month of current taxonmy term
- Create short URL with auto 301 redirect
- ACF for custom post type archive pages: which hook to use?
- 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
- Why is wp api returning old acf values?
- How to use single.php for creating, reading and editing Custom Posts with ACF
- Distribute Custom Post in different pages
- get custom post type value in header.php [closed]
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How do I replace the post title with a custom field?
- Advanced custom fields Post Object image field not displaying in custom post type single.php
- Sum and count of custom field values
- How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit
- How to export custom post type with ACF to individual file with automation?
- Custom fields not showing in custom post type
- Group by custom field value (start and end times)
- Custom post types, disable fields
- meta query not retrieving posts
- How to display a WordPress Custom Field only on a specific day of the week?
- Custom Post Type with Configurable Sidebar via ACF
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- WordPress giving a 404 page when passing a year argument different than the current year
- Custom Sidebar in Editor (not Widget) for Custom Post Type in Genesis
- ACF Relationship Posts how to show additional content
- wp-includes does not contain a feed template
- Limit search field to just search a custom post type with custom fields
- Advanced custom field – posted fields from custom post type
- Why does my URL keep returning 404 error code?
- Excerpt length: get first paragraph
- SQL query – get ids – Advanced Custom Fields / WPeC
- Custom field with Types: get custom field’s value label (of type select)
- Problem with date comparison for custom fields
- Using global $post; with custom post types
- How to display author details in a custom post type in the wordpress backend?
- Show posts associated with ACF post object and custom post type
- Show/hide posts and categories based on user meta
- Fetch data from two custom post types and create multidimensional array for output to html table
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- How can i show ACF in post excerpts
- ACF – Retrieve custom taxonomy from a relationship field
- How to set a ‘page’ as parent of a custom post type?
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Custom front-end form for adding post – Category problem
- Set up a WP Cron scheduled event to update calculated ACF field
- Query filter by value in meta_value array
- Show Post Revisions on front-end
- count & sum the value of custom field of the author post in dynamic posts
- How to show Custom Post Type – Case Study using Shortcode & ACF
- Add custom post related by custom field to custom post
- Create if else for post types in WP_Query ‘post__in’ values
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- 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
- Orderby custom fields is not working
- Custom post ID & display information related to this ID
- Using ACF values in nested WP queries for CPT with date values in the past
- How to set post date in post_type so that it’s same as latest post in category
- Create/populate Custom Posts ACF fields from external JSON file
- Display post count for a specific month
- Expire post to draft by date-picker custom field
- WordPress URL rewrites using Advanced Custom Field
- Custom Post Type and Structure Question
- Display a Custom Post Type with Advanced Custom Fields on Homepage
- CPT email notification including only new value custom fields
- Filter result of Custom Post Type using meta_query with ACF
- 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
- Query posts by current ACF meta key value on single page as related posts
- Custom sorting in post columns by ACF Pro Select Field
- Load info from customposttype into template page
- Show custom post type event if current day using ACF
- Display Custom Field or Custom Taxonomy in front page /post/product