Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I implemented a custom post type for a class post. Now every post has a additional date picker called "date_event", my question is: Any have ideas how can i order the post for the last date of the label date_event?

Thank you for your help.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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
}
share|improve this answer
    
But @micheele, can i show only the events in this weeks? –  rodboc Feb 18 '13 at 16:07
    
That's possible though slightly more complicated (and a different question than what you asked above). First I'd get it showing all your posts ordered by your date field. Then post that code in a new question and ask how to limit the display by date range. –  Michelle Feb 18 '13 at 17:43
    
Yes, you are right. Thanks for your help =) –  rodboc Feb 18 '13 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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