Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ongoing_args = array(
- 'post_type' => 'promotions',
- 'meta_key' => 'sp_ongoingPromotion',
- 'meta_value' => 1
- );
- $current_args = array(
- 'post_type' => 'promotions',
- 'meta_key' => 'sp_endDate',
- 'meta_value' => date("Y/m/d"),
- 'meta_compare' => '>=',
- 'orderby' => 'meta_value',
- 'order' => 'ASC'
- );
- // Get promotions using the arguments outlined above.
- $ongoing_promotions = get_posts( $ongoing_args );
- $current_promotions = get_posts( $current_args );
- // Merge arrays
- $all_promotions = array_merge( $ongoing_promotions, $current_promotions );
- // Get just the ID of promotions
- $promotion_ids = wp_list_pluck( $all_promotions, 'ID' );
- print_r($promotion_ids);
- // Do a new query with these IDs to get a properly-sorted list of promotions
- $args = array(
- 'post__in' => $promotion_ids,
- 'numberposts' => 5,
- 'post_status' => 'publish'
- );
- $wp_query= null;
- $wp_query = new WP_Query();
- $wp_query->query( $args );
- $wp_query = new WP_Query($args);
- if($wp_query->have_posts()){
- while($wp_query->have_posts()){
- $wp_query->the_post();
- ?>
- <li>
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- <br/>
- <span>
- <?php
- $meta = get_post_meta(get_the_ID(), 'sp_endDate', true);
- if ( '' != $meta ) {
- $formattedDate = new DateTime( $meta );
- echo "Expires: ".$formattedDate->format('F d, Y');
- }
- ?>
- </span>
- </li>
- <?php }
- } else { ?>
- <p>No Posts were found</p>
- <?php }
- wp_reset_postdata();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement