In the following shortcode, I have two variable, $today
and $tommorrow
that are being called inside a custom meta query.
function display_prognostika_home_loop($atts, $content = null) {
// Get all the categories
$taxonomy = 'diorganosi';
$today = current_time("Y-m-d");
$tomorrow = date("Y-m-d", strtotime('tomorrow'));
$parent_terms = get_terms (
array (
'taxonomy' => $taxonomy,
'parent' => 0,
'fields' => 'ids',
)
);
$terms_list = get_terms($taxonomy,
array (
'hide_empty' => true, // change to true if you don't want empty terms
'orderby' => 'name',
'order' => 'ASC',
'exclude' => $parent_terms,
)
);
ob_start();
// Loop through the $category terms
foreach ( $terms_list as $term ):
$prognostika_loop = new WP_Query(
array(
'post_type' => 'prognostika',
'showposts' => -1,
'order' => 'ASC',
'orderby' => 'prog_date_time',
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'terms' => array( $term->term_id ),
'field' => 'term_id',
)
),
'meta_query' => array(
array(
'key' => 'prog_date_time',
'value' => $today,
'compare' => '=',
'type' => 'DATE',
),
),
)
);
// output category title and posts
if($prognostika_loop->have_posts()) {
?>
<div class="gb-button-wrapper prognostiko-diorganosi-wrapper">
<span class="gb-button prognostiko-diorganosi"><span class="gb-button-text"><?php echo $term->name; ?></span>
<span class="gb-icon">
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="enable-background:new 0 0 27.965 27.965" viewBox="0 0 27.965 27.965"><path d="M23.43 12.929c-.021-.021-.043-.034-.064-.052-.025-.029-.047-.061-.07-.09l-6.273-6.269c-.812-.813-2.099-.845-2.871-.071-.773.772-.741 2.061.071 2.872l3.054 3.056H5.967a1.981 1.981 0 1 0 0 3.962h11.254l-3.041 3.037c-.824.826-.867 2.122-.094 2.896.775.772 2.069.731 2.895-.095l6.354-6.354c.826-.824.868-2.12.095-2.892z" style="fill:#030104"></path><path d="M13.983 0C6.262 0 0 6.261 0 13.985c0 7.721 6.262 13.979 13.983 13.979 7.724 0 13.982-6.259 13.982-13.979C27.966 6.261 21.707 0 13.983 0zm0 26.535c-6.933 0-12.551-5.619-12.551-12.549 0-6.934 5.619-12.551 12.551-12.551s12.551 5.617 12.551 12.551c0 6.93-5.619 12.549-12.551 12.549z" style="fill:#030104"></path>
</svg>
</span>
</span>
</div>
<?php
//$cat_object = $prognostika_loop->get_queried_object();
//$cats = $cat_object->count;
//var_dump ($cat_object);
while ($prognostika_loop->have_posts()) : $prognostika_loop->the_post();
do_action('prognostika_loop');
endwhile;
}
// Reset query
$customQuery = null;
wp_reset_postdata();
// end the loop
endforeach;
return ob_get_clean();
}
add_shortcode('prognostika_home_loop', 'display_prognostika_home_loop');
I would like to set up attributes so that
[prognostika_home_loop today]
- Display today's posts
[prognostika_home_loop tomorrow]
- Display tomorrow's posts
meaning today
and tomorrow
would affect the 'value'=> $today
pair. When today is used, pair would become 'value' => $today
. When tomorrow is used, pair would become 'value' => $tomorrow
.