Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. $current_taxonomy = get_query_var( 'taxonomy' );
  2. $current_term = get_query_var( 'term' );
  3.  
  4.  
  5. // projects are filtered by term
  6. if( $current_taxonomy && $current_term ) {
  7. $projects = get_posts(
  8. array(
  9. 'post_type' => 'my-post-type',
  10. 'posts_per_page' => 10,
  11. 'tax_query' => array(
  12. array(
  13. 'taxonomy' => 'my-taxonomy',
  14. 'field' => 'slug',
  15. 'terms' => $term->slug
  16. )
  17. )
  18. )
  19. );
  20.  
  21. if( $projects ) {
  22. foreach( $projects as $project ) {
  23. ?>
  24. <section class="">
  25. <?php
  26. echo $project->post_title;
  27. ?>
  28. </section>
  29. <?php
  30. }
  31. }
  32.  
  33. } else {
  34. // projects are not filtered
  35. // we show projects by all terms
  36. $terms = get_terms(
  37. array(
  38. 'my-taxonomy'
  39. ),
  40. array(
  41. 'orderby' => 'name',
  42. 'order' => 'ASC',
  43. 'hide_empty' => true
  44. )
  45. );
  46.  
  47. foreach( $terms as $term ) {
  48.  
  49. $projects = get_posts(
  50. array(
  51. 'post_type' => 'my-post-type',
  52. 'posts_per_page' => 10,
  53. 'tax_query' => array(
  54. array(
  55. 'taxonomy' => 'my-taxonomy',
  56. 'field' => 'slug',
  57. 'terms' => $term->slug
  58. )
  59. )
  60. )
  61. );
  62.  
  63. if( $projects ) {
  64. foreach( $projects as $project ) {
  65. ?>
  66. <section class="">
  67. <?php
  68. echo $project->post_title;
  69. ?>
  70. </section>
  71. <?php
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement