Date range custom fields wordpress wp_query

Posted: March 2, 2015 in web
...
    function sc_events($atts) {
        $a = shortcode_atts(array(
            'type' => 'nyec-events',
            'from_date' => '',
            'to_date' => '',
                ), $atts);

        $metaQry = '';
        if ($a['from_date'] != '' && $a['to_date'] != '') {
            $metaQry = array(
                array(
                    'key' => 'date',
                    'value' => array($a['from_date'], $a['to_date']),
                    'compare' => 'BETWEEN',
                    'type' => 'DATE'
                )
            );
        }
        $args = array('post_type' => 'event', 
            'category_name' => $a['type'], 
            'meta_key' => 'date', 
            'orderby' => 'meta_value_num', 
            //'meta_query' => $metaQry,
            'order' => 'ASC');
        
        $loop = new WP_Query($args);
        $str = '<div class="row"><div class="col-md-3"><h2 class="inner-title">Date</h2></div><div class="col-md-3"><h2 class="inner-title">Location</h2></div><div class="col-md-6"><h2 class="inner-title">Description</h2></div></div>';
        while ($loop->have_posts()) : $loop->the_post();
...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s