WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


i am building a complex cinema site, and i want to get movies by date

Ex: The movies are aded trought post type,

I have a custom field name date.

How can i retrive the Movie that shoud play today in cinema ( date in custom field : 08.09.2012...)

Ex: How can i retrive the movie by date

Site: http://cinema.trancelevel.com/cinema/in-curand/

Movies that apear today...in righit

Like This? `

$args = array(
    'posts_per_page' => '-1',
    'post_type' => 'post',
    'meta_key' => 'premiera_cinema',
    'meta_value' => date('Y-m-d'),
    'meta_compare' => '='
$todays_movies = new WP_Query( $args );

<?php while ($todays_movies->have_posts()) : $todays_movies->the_post(); ?>
<div class="sidebar-titlu"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="sidebar-stiri">
<img src="/scripts/timthumb.php?src=<?php the_field('img'); ?>&h=60&w=90&zc=1" alt="" title="<?php the_title(); ?>" />
<?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">...detalii</a>
<?php endwhile; ?>
share|improve this question
tomorrow i want to get the movies that play tomorrow, i want to get the post automate by live date, and if there is no movie i want to display a message , no movie this day – Batman Sep 7 '12 at 23:09
have you researched something like: css-tricks.com/snippets/wordpress/… – helgatheviking Sep 7 '12 at 23:26
up vote 1 down vote accepted

To be able to query on your dates beyond a simple date comparison you should reverse the format of your date field. Dates should always follow the MySQL date format for reliable querying and sorting: YYYY-MM-DD HH:MM:SS

To query movies for today you would use a meta query:

$args = array(
    'posts_per_page' => '-1',
    'post_type' => 'movie',
    'meta_key' => '_date_key',
    'meta_value' => date('Y-m-d'),
    'meta_compare' => '='

$todays_movies = new WP_Query( $args );
share|improve this answer

First you'll need to dynamically get todays data formatted the same as what you store in the custom field like this:

$today = date('m.d.Y');

Then make a new query that gets one movie with a custom field called "date" that has the value of $today, like this:

$q = new WP_Query('post_type=movies&posts_per_page=1&meta_key=date&meta_value='.$today);

Then run a loop with that query. Every day the $today variable will change, and so will the movie returned. NOTE: you may have to define your timezone before using the date() function so the $today variable is updated at midnight your time. Set your timezone using this function: date_default_timezone_set()

Here is a list of supported timezones you can enter as the parameter for the above function: http://php.net/manual/en/timezones.php

share|improve this answer
Query strings are called "deprecated" these days. They work, but you shouldn't use them anymore. – kaiser Sep 8 '12 at 0:09

Your Answer


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.