Skip to content

Instantly share code, notes, and snippets.

@imgiseverything
Created March 22, 2012 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imgiseverything/2157663 to your computer and use it in GitHub Desktop.
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 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