Skip to content

Instantly share code, notes, and snippets.

@kisildev
Last active April 12, 2019 15:46
Show Gist options
  • Save kisildev/15b7de7d93a86ed866e394a92fec5365 to your computer and use it in GitHub Desktop.
Save kisildev/15b7de7d93a86ed866e394a92fec5365 to your computer and use it in GitHub Desktop.
WP taxonomy. WP_tax.
<?php
$term_id = 10;
$taxonomy_name = 'products';
$term_children = get_term_children( $term_id, $taxonomy_name );
echo '<ul>';
foreach ( $term_children as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
<?php global $post; ?>
<?php if($post_terms = get_the_terms( $post, 'taxonomy_slug' )): ?>
<div class="subtitle"><?php echo $post_terms[0]->name; ?></div>
<?php endif; ?>
ACF relation with dinamic terms
<?php if( $post_arr): ?>
<?php foreach( $post_arr as $post): ?>
<?php setup_postdata($post); ?>
<div class="post">
<div class="post__inner">
<a href="<?php the_permalink(); ?>" class="post-link">
<?php if ($view_subtitle && $header_view == 'title'): ?>
<div class="subtitle subtitle--gray"><?php echo $view_subtitle; ?></div>
<?php elseif( ($post_terms = wp_get_object_terms($post->ID, get_object_taxonomies($post->post_type))) && $header_view == 'cat'): ?>
<div class="subtitle subtitle--gray"><?php echo $post_terms[0]->name; ?></div>
<?php endif; ?>
<h2 class="post__title"><?php the_title(); ?></h2>
<div class="post__excerpt"><?php the_excerpt(); ?></div>
<span class="arrow icon-arrow-right1"></span>
</a>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
@kisildev
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment