Tell us what you are trying to do?
create Elementor custom query:
I have custom posts type: event
I have a custom field: event-date
this is the query I tried:
add_action( 'elementor_pro/posts/query/upcoming', function( $query ){
$query->set('post_type', 'event');
$today = Date('Y-m-d');
$query->set('meta_query', array(
'start_date' => array(
'key' => 'wpcf-event-date',
'value' => $today,
'compare' => '>=',
)
));
$query->set('orderby', array('start_date'=>'ASC'));
} );
What is the link to your site?
hidden link
as you can see this code bring 0 results
Can you help me?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Barak,
Thank you for getting in touch.
The issue here is that the date field is stored as a timestamp. You function is passing the date into the query as a calendar date which won't work.
What you need to do is convert that date to a timestamp using the strtotime() function.
This should allow you to convert your date variable and allow the filter to work as intended.
Please let me know if this helps.
Thanks,
Shane
Can you help me how to edit the code?
I am not a developer
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Barak,
Sure the correct code would be.
add_action( 'elementor_pro/posts/query/upcoming', function( $query ){
$query->set('post_type', 'event');
$today = Date('Y-m-d');
$query->set('meta_query', array(
'start_date' => array(
'key' => 'wpcf-event-date',
'value' => strtotime($today),
'compare' => '>=',
)
));
$query->set('orderby', array('start_date'=>'ASC'));
} );
Please let me know if this helps.
Thanks,
Shane