Sunday, November 20, 2022
HomeWordPress Developmentphrases - Checklist posts grouped by kids of a customized taxonomy

phrases – Checklist posts grouped by kids of a customized taxonomy


I’m efficiently itemizing posts grouped by class from a customized taxonomy like so:

Class 1

Class 2

Class 3

Class 4

I’m making an attempt to solely checklist teams of classes (with their posts) which are descendants of dad or mum classes. For instance, if Class 1 is the dad or mum of Class 2 and Class 3 is the dad or mum of Class 4, I solely need to checklist:

Class 2

Class 4

The code I have already got lists all posts grouped by all classes, dad or mum or kids:

$taxonomy = 'diorganosi';
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$tax_terms = get_terms(  $taxonomy,
  array(
    'dad or mum' => $term_id,
    'hide_empty' => true, // change to true if you don't need empty phrases
    'orderby' => 'title',
    'order' => 'DESC',
    'fields' => 'names', // return the time period names solely
  )
);

foreach($tax_terms as $tax_term) { // loop by means of the phrases
  echo '<h2>' . $tax_term . '</h2>'; // echo the time period title as a h2
  $term_posts = get_posts( // discover posts with the proper time period
    array(
      'no_found_rows' => true, // for efficiency
      'ignore_sticky_posts' => true, // for efficiency
      'post_type' => 'prognostika',
      'posts_per_page' => -1, // return all outcomes
      'tax_query' => array( // https://developer.wordpress.org/reference/courses/wp_tax_query/
        array(
              'taxonomy' => $taxonomy,
              'discipline'    => 'title',
              'phrases'    => array( $tax_term )
          )
      ),
      'fields' => 'ids', // return the submit IDs solely
    )
  );
  
  echo '<ul>'; // open bullet checklist
  foreach($term_posts as $term_post_id) { // loop by means of posts
    $post_title = get_the_title($term_post_id); // get submit title
    $post_permalink = get_the_permalink($term_post_id); // get submit hyperlink
    echo '<li>'; // open checklist merchandise
    echo '<a href="' . $post_permalink . '">' . $post_title . '</a>'; // add hyperlink to submit with submit title as hyperlink textual content
    echo '</li>'; // shut checklist merchandise
  }
  echo '</ul>'; // shut bullet checklist
}

As you possibly can see, I attempted including:

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;

then referencing 'dad or mum' => $term_id inside get_terms however no luck.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments