Creating archive.php in wordpress using custom field

3

I'm trying to create a calendar page in WordPress where the user selects the month by a select :

<select>
     <option>Janeiro 2015</option>
     <option>Dezembro 2014</option>
     <option>Novembro 2014</option>
     <option>Outubro 2014</option>
     <option>Setembro 2014</option>
</select>

Then the posts are loaded via Ajax. I created a form of type POST called agenda and a custom field called agenda_data .

I need help with two items, the rest I think I can unroll myself.

  • No select appear the last 12 months, the WordPress function wp_get_archives does this. But it returns based on the publication dates and I would like it to be based on the date of the custom field.

  • A archive.php that displays the posts also based on the date of the custom field and not the post date of the post.

  • I did not find anything yet on the internet that could help me.

        
    asked by anonymous 14.02.2015 / 02:40

    1 answer

    1

    It does not look like much, 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: link

    As for the page archive.php , instead of the traditional <?php if( have_posts() ) : ?> , you have to do a custom WP_Query , using the parameters Order & Orderby :

    '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 to the archive.php template the way it is.

    References:
    - 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 response is a master class )     

    13.10.2015 / 05:16