0

This code retrive me the movies that are comming in cinema, i want to be able to list movies that apear this day, next day ... 7 day week

Ex: Today is 13.05.2013, i want to list the movies that apear this day ( - the code down list me all the movies that are comming)... and if the day pass to 14.05 i want the box post disapear from page.

The code down do that but it display all upcomming movies. I want to list only today movies

Something like this : http://tvpedia.org/program-tv

How can i do that?

Thanks in advance

 <?php // Get today's date in the right format
    $todaysDate = date('Ymd');
    ?>
    <?php $loop = new WP_Query( array(
    'post_type' => 'post',
    'posts_per_page' =>3,
    'meta_key' => 'premiera_cinema',
    'meta_compare' => '>=',
    'meta_value' => $todaysDate,
    'orderby' => 'meta_value',
    'order' => 'ASC'
    ) ); ?>
    <?php while ($loop->have_posts()) : $loop->the_post(); ?>
7
  • I bet the content of meta_value is not a date formatted with Ymd. Normally it is formatted with Y-m-d
    – Ralf912
    Commented May 12, 2013 at 23:45
  • the format is yymmdd
    – Batman
    Commented May 12, 2013 at 23:49
  • Problem solved?
    – Ralf912
    Commented May 12, 2013 at 23:50
  • this code up work's but i need to get only for all 7 days of week separate.
    – Batman
    Commented May 12, 2013 at 23:50
  • This answer show you how.
    – Ralf912
    Commented May 12, 2013 at 23:53

1 Answer 1

1

What you want to do in this case is to use a meta_query in WP_Query like the following. You can reference the following Codex for more information https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters. Once you have the posts. Loop over them and add their date as data attribute, and filter the items using data attributes.

$args = array(
    'post_type' => 'post',
    'meta_query' => array(
        array(
            'key'       => 'premiera_cinema',
            //Beginning and End date in format of YYYYMMDD
            'value'     => array( 20130101, 20130107 ),
            'type'      => 'date',
            'compare' => 'BETWEEN'
        )
    )
);
$query = new WP_Query( $args );
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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