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?

2
  • 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. Mar 16, 2013 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, 2013 at 19:53

1 Answer 1

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
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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