Custom Post Types relationships

I have a custom post type for my videos. I need do related it with other post category. And i have 10 category

Like this :

Read More
Post Category - Video Category
Tech            Tech
Marketing       Marketing
News            News
.....................

I want to do for this. I have a post Category Tech and I have custom post type Category(Taxonomy) Tech..

When I currently viewing Tech (Post) Category, How can i list (on sidebar) Tech videos?

Related posts

Leave a Reply

1 comment

  1. From your question I gather your taxonomy term names match your category names. If this is the case and always will be the case, why not just query your custom post type by category slugs? Not sure what the exact name is, so I just made it video.

    // get category slug
    $cat = get_category( get_query_var( 'cat' ) );
    $cat_slug = $cat->slug;
    
    // query your custom post type (video?), assuming 
    // slugs match for your category name and taxonomy term name
    $my_args = array(
        'post_type' => 'video',
        'tax_query' => array(
            array(
                'taxonomy' => 'your_taxonomy_name',
                'field' => 'slug',
                'terms' => $cat_slug
            )
        )
    );
    
    $my_query = new WP_Query($my_args);
    
    while ($my_query->have_posts()) {
        $my_query->the_post();
        // do the usual thing
    }