I would like to display my custom post type by specific order.
In my custom post type, i've 2 meta :
- DAY ( Select : 1,2,3,4,5,etc...)
- MONTH ( Select : Janvier, Fevrier, Mars, Avril, etc...)

How it's possible to display this :

  • DISPLAY CUSTOM POST TYPE BY DATE ( closest at first ).


  • You have only month and day fields? You don't store year value? Do you store these values as one or 2 separate custom fields? – Krzysiek Dróżdż Jul 1 '13 at 15:37
  • 2
    I don't think there's really any point in storing the day and month separately, it's far simpler to query on a single field containing yyyy-mm-dd, and day and month can be easily extracted from this format for display. – Milo Jul 1 '13 at 15:44
  • How does your day and month data differ from the day and month stored by WordPress? This seems like unnecessary complication. – s_ha_dum Jul 1 '13 at 15:46
  • Yes i've YEAR value, but if i know how do this with 2 values, i think it will be simple for 3 values :). Values are in 2 separate field. – PixelBBW Jul 1 '13 at 15:54
  • @s_ha_dum because it's not post date, but the event date ;). – PixelBBW Jul 1 '13 at 15:55

Save your data in a single field as either YYYY-MM-DD or UNIXTIME. Then query like this:

$args = array(
    'post_type' => 'POST_TYPE_NAME',
    'meta_key' => 'date-key-name',
    'orderby' => 'meta_value',
    'order' => 'ASC',
$query = new WP_Query( $args );

You should get an order, unless I am having a bad morning, of Day -> Month -> Year, which I believe is what you want. I don't have your data at hand so I can't actually test that.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.