Skip to content

Instantly share code, notes, and snippets.

@DarioBF
Created July 28, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarioBF/d3960fea70ffc10b9de3b195052358dd to your computer and use it in GitHub Desktop.
Save DarioBF/d3960fea70ffc10b9de3b195052358dd to your computer and use it in GitHub Desktop.
function convuls_customquery(){
// Set the arguments based on our get parameters
$today = date('Ymd',strtotime('today'));
$args = array (
'post_type' => 'evento',
'posts_per_page' => -1,
'meta_key' => 'fecha',
'meta_query' => array(
'event_selected' =>array(
'key' => 'evento_seleccionado',
'value' => '1',
'compare' => '=',
),
'relation' => 'AND',
'start_date' =>array(
'key' => 'fecha',
'compare' => '>=',
'value' => $today,
),
'start_time' => array(
'key' => 'hora',
'compare' => 'EXISTS',
)
),
'orderby' => array(
'start_date' => 'ASC',
'start_time' => 'ASC'
)
);
// Run a custom query
$meta_query = new WP_Query($args);
if($meta_query->have_posts()) {
//Define and empty array
$i = 0;
$data = array();
// Store each post's data in the array
while($meta_query->have_posts()) {
$meta_query->the_post();
$data[$i]['title'] = get_the_title();
$data[$i]['excerpt'] = get_the_excerpt();
$data[$i]['type'] = get_the_terms(get_the_ID(), 'tipo-de-evento');
$data[$i]['date'] = get_field('fecha', get_the_ID());
$data[$i]['time'] = get_field('hora', get_the_ID());
$data[$i]['thumbnail'] = get_the_post_thumbnail_url(get_the_ID(), 'thumbnail');
$data[$i]['link'] = get_the_permalink();
$i++;
}
// Return the data
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment