Last active
September 4, 2019 22:23
-
-
Save MACscr/c310361b07af6677015f62c1ce4ceef9 to your computer and use it in GitHub Desktop.
Trying to create this shortcode to get results from program_ids (can be multiple), then order the results by date, then group by series id if it has one, then limit number of results to whatever limit is specified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function northwoods_events_shortcode($atts) { | |
$limit = 10; | |
if ($atts['limit']) { | |
$atts['limit'] = (int)$atts['limit']; | |
} | |
$args = array( | |
'post_type' => 'northwoods_events', | |
'post_status' => 'publish', | |
'meta_query' => array( | |
array( | |
'key' => 'program_id', | |
'value' => explode(',',$atts['program_id']), | |
'compare' => 'IN' | |
), | |
array( | |
'key' => 'event_datetime', | |
'value' => date('Y-m-d H:i:s'), | |
'compare' => '>' | |
) | |
), | |
'meta_key' => 'event_datetime', // 2019-11-01T16:00:00 | |
'meta_type' => 'DATETIME', | |
'orderby' => 'meta_value_datetime', | |
'order' => 'ASC', | |
'posts_per_page' => $limit, | |
); | |
/* | |
// GROUP BY | |
'meta_key' => 'series_id' | |
*/ | |
#var_dump($args);die(); | |
$events = new WP_Query( $args ); | |
if( $events->have_posts() ) : | |
while ( $events->have_posts() ) : $events->the_post(); ?> | |
<?php | |
$event_date = get_post_meta( get_the_ID(),'event_datetime' ); | |
$event_date_create = date_create($event_date[0]); | |
$event_id = implode(get_post_meta( get_the_ID(),'event_id')); | |
$event_location = implode(get_post_meta( get_the_ID(),'event_location')); | |
$event_url = "https://my.northwoods.church/portal/event_detail.aspx?id=".$event_id; | |
$event_image = implode(get_post_meta( get_the_ID(),'event_image')); | |
?> | |
<hr> | |
<div class="row"> | |
<div class="col-lg-3"> | |
<a href="<?php echo $event_url;?>"> | |
<img width="285" height="148" src="<?php echo $event_image;?>" class="attachment-full size-full wp-post-image" alt="" srcset="<?php echo $event_image;?> 285w, <?php echo $event_image;?> 160w" sizes="(max-width: 285px) 100vw, 285px"> | |
</a> | |
</div> | |
<div class="col-lg-9"> | |
<a href="<?php echo $event_url;?>"> | |
<h1><?php the_title(); ?></h1> | |
</a> | |
<p><?php echo date_format($event_date_create,'F j, Y');?> | <?php echo date_format($event_date_create,'g:ia');?> | <?php if ($event_location) { ?><?php echo $event_location;?><?php } ?></p> | |
<?php the_excerpt(); ?> | |
</div> | |
</div><!--end row --> | |
<?php endwhile; | |
endif; | |
} | |
add_shortcode( 'northwoods_events', 'northwoods_events_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment