Guest User

Untitled

a guest
Apr 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. add_filter( 'getarchives_where', 'wse95776_archives_by_cat', 10, 2 );
  2. /**
  3. * Filter the posts by category slug
  4. * @param $where
  5. * @param $r
  6. *
  7. * @return string
  8. */
  9. function wse95776_archives_by_cat( $where, $r ){
  10. return "WHERE wp_posts.post_type = 'post' AND wp_posts.post_status = 'publish' AND wp_terms.slug = 'BLOGCATEGORY' AND wp_term_taxonomy.taxonomy = 'category'";
  11. }
  12.  
  13. add_filter( 'getarchives_join', 'wse95776_archives_join', 10, 2 );
  14.  
  15. /**
  16. * Defines the necessary joins to query the terms
  17. * @param $join
  18. * @param $r
  19. *
  20. * @return string
  21. */
  22. function wse95776_archives_join( $join, $r ){
  23. return 'inner join wp_term_relationships on wp_posts.ID = wp_term_relationships.object_id inner join wp_term_taxonomy on wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id inner join wp_terms on wp_term_taxonomy.term_id = wp_terms.term_id';
  24. }
  25.  
  26. echo '<ul class="blog-archive"><li>'.wp_get_archives( array( 'type' => 'monthly', 'format' => 'li', 'show_post_count' => 1, 'include'=>1 ) ).'</li></ul>';
Add Comment
Please, Sign In to add comment