Created
March 22, 2012 10:53
-
-
Save imgiseverything/2157663 to your computer and use it in GitHub Desktop.
IMG Custom Post Types: Retreiving custom post types and ordering by a date field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will get all posts whose 'event_date' is today or later ordered by closest date | |
$custom_posts = get_posts(array( | |
'meta_compare' => '>', | |
'meta_key' => 'event_date_strtotime', // <- this is your custom field (see notes below) | |
'meta_value' => strtotime('-1 day'), | |
'numberposts' => 4, | |
'order' => 'ASC', | |
'orderby' => 'meta_value', | |
'post_type' => 'event' // <- this is the name of your custom post type | |
)); | |
/* | |
Notes: | |
! This custom field you will have called 'event_date'. The plugin automatically creates another custom meta field called | |
your_custom_field_strtotime which stores a timestamp of the date value. You don't need to worry about it | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment