Last active
April 12, 2019 15:46
-
-
Save kisildev/15b7de7d93a86ed866e394a92fec5365 to your computer and use it in GitHub Desktop.
WP taxonomy. WP_tax.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get chirdren of taxonomy - https://codex.wordpress.org/Function_Reference/get_term_children