Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.