SHARE
TWEET

Untitled

a guest Oct 12th, 2011 28 Never
  1. //Query News posts
  2. add_filter('query_vars', 'add_my_queryvars' );
  3. function add_my_queryvars ( $qvars ){
  4.     $qvars[] = ‘newsdate’;
  5.   return $qvars;
  6. }
  7.  
  8. //Call the news template
  9. add_filter('template_include', 'set_my_template');
  10. function set_my_template( $template ){
  11.     global $wp_query;
  12.     if( isset( $wp_query->query_vars['newsdate'] )) {
  13.         $template = locate_template( 'page-all-news.php');
  14.     }
  15.     return $template;
  16. }
  17.  
  18. add_filter('posts_where', 'my_reviews_where' );
  19. function my_reviews_where( $where ){
  20.     global $wp_query, $wpdb;
  21.     if( isset( $wp_query->query_vars['newsdate'] )) {
  22.         $author = $wp_query->query_vars['newsdate'];
  23.         $where .= " AND m.meta_key = 'post_date'";
  24.     }
  25.     return $where;
  26. }
  27.  
  28. add_action('generate_rewrite_rules', 'my_rewrite_rules');
  29. function my_rewrite_rules( $wp_rewrite ) {
  30.   $new_rules = array(
  31.      'news/(.+)' => 'index.php?newsdate=' .
  32.        $wp_rewrite->preg_index(1),
  33.        );
  34.  
  35.   // Add the new rewrite rule into the top of the global rules array
  36.   $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
  37. }
  38.  
RAW Paste Data
Top