Skip to main content
6 of 7
added 6 characters in body
cybmeta
  • 20.6k
  • 5
  • 47
  • 56

I think your are missing some concepts or not fully understanding.

  1. A taxonomy is a way to group things, ie, posts. The same taxonomy can be used for several post types, so a taxonomy is not under a post.
  2. The single template files are used for the view of a single post. You can make a different single template for each post type, even for each individual post.
  3. The specific template for a term of a taxonomy is taxonomy-{your_taxonomy}-{term}.php, in your case, it would be for example taxonomy-type-radio.php. This template will show all posts within the term radio of the 'type' taxonomy.

I think what you really want is to use a different single template based on the term of the taxonomy "type" associated to a 'Ad' post. I assume only one term of 'type' taxonomy can be selected per post. You can use template_include filter, or more specifically, the single_template filter:

<?php
function get_custom_single_template($single_template) {
    global $post;

    if ($post->post_type == 'ad') {
        $terms = get_the_terms($post->ID, 'type');
        if($terms && !is_wp_error( $terms )) {
            //Make a foreach because $terms is an array but it supposed to be only one term
            foreach($terms as $term){
                $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php';
            }
        }
     }
     return $single_template;
}

add_filter( "single_template", "get_custom_single_template" ) ;
?>

Put this in the functions.php file of your theme. Don't forget to create the single-*.php for each term (single-radio.php, single-tx.php, etc)

cybmeta
  • 20.6k
  • 5
  • 47
  • 56