Custom filtering and sorting for events via functions.php


/ Published in: PHP
Save to your folder(s)

Uses action hook of the hybrid theme framework to launch function that modifies the query on the archive page for category 6.\\r\\n\\r\\nSorts by the custom field \\\"event_date\\\" and compares it to the current date.\\r\\n\\r\\nBased on [goto11\\\'s](http://www.goto11.co.uk/) code from the discussion [here](http://esdev.net/sort-events-by-date-in-wordpress-using-custom-fields/comment-page-1/#comment-7111)


Copy this code and paste it in your HTML
  1. /* Custom sorting for Events. */
  2. add_action( 'hybrid_before_content', 'events_sorting' );
  3. function events_sorting() {
  4. if ( is_category('6') ) {
  5. $today = date('Y-m-d');
  6. query_posts('cat=6&meta_key=event_date&meta_compare=>=&meta_value='.$today.'&orderby=meta_value&order=ASC');
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.