I have custom post type. In this custom post type I have custom field with date in format: 23/09/2012
How to show only posts, which currently date is before date from these custom field?
Sory for my english.
Tom
I have custom post type. In this custom post type I have custom field with date in format: 23/09/2012
How to show only posts, which currently date is before date from these custom field?
Sory for my english.
Tom
You can do this using query_posts()
or a new WP_Query
object. Here's an example:
query_posts( array(
'post_type' => 'my_post_type',
'meta_query' => array(
array(
'key' => 'my_date_field_key',
'value' => date( 'd/m/Y' ),
'compare' => '<',
'type' => 'DATE'
)
)
) );
if ( have_posts() ) : while( have_posts() ) : the_post();
// your loop code here
the_title('<h2>','</h2>');
endwhile; endif;
wp_reset_query();
NOTE:
If you want to order by date this is a little trickier unless you store the date as a unix timestamp. Then you can orderby meta_value_num as it's just a number.
the_title()
– sanchothefat
Mar 15 '12 at 13:03