I'm trying to create a calendar page in WordPress where the user selects the month by a
<select> <option>Janeiro 2015</option> <option>Dezembro 2014</option> <option>Novembro 2014</option> <option>Outubro 2014</option> <option>Setembro 2014</option> </select>
Posts are then loaded via Ajax. I created a
POST form called
agenda and a custom field called
I need help on two items, the rest I think I can unroll on my own.
selectthe last 12 months appear, the WordPress function
wp_get_archivesdoes this. However it returns based on the published dates and I would like it to be based on the date of the custom field.
archive.phpthat displays the posts also based on the custom field date and not the post publish date.
I haven't found anything on the internet that could help me.
It seems that there is not much way, the filters available in the
wp_get_archives function are not enough to do this filtering. The solution is to copy the function to a
meu_get_archives($args) and adapt it to your needs: https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/general-template.php #L1354
'order' => 'ASC', 'orderby' => 'meta_val_num'
Or you could use the
pre_get_posts filter, which is recommended to filter the main query and leave the
archive.php template as it is.
– Order Custom Post Type Archive by multiple values in functions.php
– Archive Listings Filtered by Date Values in a Custom Field/Post Meta? (here Mike Schinkel's answer is a master class )