1

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 :

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?

  • Take a look at wordpress.org/extend/plugins/posts-to-posts - it allows for connecting post types and there are shortcodes and functions for listing them accordingly. – Mario Peshev Mar 16 '13 at 19:16
  • Thanks @MarioPeshev, it is just about Post to Post i need Category(post category) to Category(Custom Post Taxonomy Term). – Genxer Mar 16 '13 at 19:53
3

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
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.