I have a code snippet showing related posts by category:

<div class="under-video-block">
<?php if ( is_active_sidebar( 'under_video' ) && is_single() ) :
    dynamic_sidebar( 'under_video' ); ?>
<?php else : ?>
    <?php //$nb_videos_related = get_theme_mod('wpsevst_nb_videos_related', '10');
    $related = get_posts( array(
        'category__in' => wp_get_post_categories($post->ID),
        'numberposts' => xbox_get_field_value( 'wpst-options', 'related-videos-number' ),
        'post__not_in' => array($post->ID)
    ); ?>
    <?php if ($related) : ?>
        <h2 class="widget-title"><?php esc_html_e( 'Related videos', 'wpst' ); ?></h2>

            if( $related ) foreach( $related as $post ) {
                get_template_part( 'template-parts/loop', 'video' );
        <?php wp_reset_postdata();  

        $category = get_the_category($post->ID); ?>
        <div class="clear"></div>
        <div class="show-more-related">
            <a class="button large" href="<?php echo get_category_link($category[0]->term_id); ?>"><?php esc_html_e('Show more related videos', 'wpst'); ?></a>
        <?php endif; ?>

<?php endif; ?>

I want to edit the above code to show a related post under a custom taxonomy called "director". What I have to do? I am an amateur who looks forward to helping. Thanks

  • To get posts from custom taxonomy replace 'category__in' parameter in get_posts() to 'tax_query'. – nmr Aug 28 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.