I have 2 custom meta one for the start date of my event and one for the end date of my event and I need to order my events according to the start date and to remove them when the end date is over.
Meta:
Start date: date_de_levenvement
End date: date_de_fin
Here is my loop:
<?php query_posts( 'post_type=agenda&meta_key=date_de_fin&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$date = get_field('date_de_fin');
$newDate = date("d/m/Y", strtotime($date)); ?>
Just need to change the query but I don’t know how to use 2 parameters with the meta value. &orderby=meta_value
needs to be something like &orderby="date_de_levenement"
I would actually use the more robust WP_Query object to accomplish this task. More specifically, you can see the section called Custom Field Parameters and see the example titled Multiple Custom Field Handling. You can create your arguments array like so:
Explanation
The
meta_query
element is an array of arrays which means you can even filter against multiple meta (custom field) properties if you wish. Notice that I included themeta_key
element. This is what will allow you to sort by your start date. Whereas thekey
element of themeta_query
element is what will filter your end date posts. (In this situation, post types namedagenda
will only be included if theirdate_de_fin
is greater than or equal to “today”.[edit]
Note that the “today” date should be formatted in SQL format like so:
Hope this helps a bit. Have fun!