Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. function get_posts_per_taxterm($taxonomy, $term_id ){
  2. $posts = get_posts(
  3. array(
  4. 'posts_per_page' => -1,
  5. 'post_type' => 'post',
  6. 'orderby' => 'menu_order',
  7. 'order' => 'ASC',
  8. 'tax_query' => array(
  9. array(
  10. 'taxonomy' => $taxonomy,
  11. 'field' => 'term_id',
  12. 'terms' => $term_id,
  13. 'include_children' => false
  14. )
  15. )
  16. )
  17. );
  18. // `first_post_id` is a global variable which contains the ID of the post which comes first inside TOC
  19. // @toDo Find a better way
  20. global $first_post_id;
  21. if(!isset($first_post_id)){
  22. if (!empty($posts)){
  23. $first_post_id = $posts[0]->ID;
  24. }
  25. }
  26. return $posts;
  27. }
  28. function get_array_of_posts_grouped_by_taxterms($terms, $parent_id = 0, $outputs = []) {
  29. foreach ($terms as $term) {
  30. if ($parent_id == $term->parent) {
  31. $outputs['<a data-id = "'.$term->term_id.'" class = "elementor-kb-term-href stm-content" href ='.get_term_link($term->term_id).'>'.$term->name.'</a>'] = get_array_of_posts_grouped_by_taxterms( $terms, $term->term_id);
  32. $posts= get_posts_per_taxterm('category',$term->term_id);
  33. foreach ($posts as $post){
  34. $outputs['<a data-id = "'.$term->term_id.'" class = "elementor-kb-term-href stm-content" href ='.get_term_link($term->term_id).'>'.$term->name.'</a>'][] = '<a class = "elementor-kb-post-href stm-content" href='.get_permalink($post->ID).' data-id="'.$post->ID.'">'.$post->post_title.'</a>';
  35. }
  36. }
  37. }
  38. return $outputs;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement