I am currently making a custom Wordpress theme, but so far I am stuck at this little problem. I have created this custom post type. And in that page (media.php) I want to be able to click on the tags, which will take me to the tag page (tag.php) and from there it will only show the post under that tag I clicked on, but right now if I click on tag 1, it will take me to tag.php, but will show ALL media post, instead of the page with clicked tag.

I have made a Custom Post type in functions.php

add Custom Post Type (functions.php)

add_action( 'init', 'media_' );
function media_() {
register_post_type( 'media', array(
  'labels' => array(
    'name' => 'Media Post',
    'singular_name' => 'Media',
  'description' => 'The Media.',
  'public' => true,
  'menu_position' => 21,
  'supports' => array( 'title', 'editor'),
  'taxonomies' => array('post_tag')


and then my page custom page template will loop the tags like this

loop the tags in custom page template (media.php)

    $archive_tags = post_type_tags( 'media' );

    foreach( $archive_tags as $tag ) 
                echo '<li><ahref="' 
                          . get_tag_link( $tag->term_id )
                          . '">' 
                          . esc_html( $tag->name ) 
                          . '</a></li>';

and then I will loop through all the custom post with the post_type name 'Media'

Loop the post (media.php)

    $args = array( 'post_type' => 'Media');
    $loop = new WP_Query( $args );
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php the_content(); ?>                             
<?php endwhile; ?>

this work, I can see all the different tags, and the post in media.php. But the thing is when I go to tag.php. It just shows all the post in media.php with that post_type name.

What should I write in tag.php?

For reference, my code in tag.php look like this so far. and it looks just like media.php.

looping the post, dosn't work (tag.php)

        $args = array( 'post_type' => 'Media');
        $loop = new WP_Query( $args );
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <?php the_content(); ?>                             
    <?php endwhile; ?> 



  1. Post 1, tag: a, b
  2. Post 2, tag: a
  3. Post 3, tag: b

then there is this list with all the tags available

  • tag a
  • tag b

so lets say I click on tag a. It will rederict me to tag.php

But instead of showing me all the post like this

  1. Post 1, tag: a, b
  2. Post 3, tag: b it is showing all the post from media.php.

NOTE ** I only want it to display the post from my custom-post-type: Media

  • It's not entirely clear what you're asking. Please clarify what it is exactly that you're trying to achieve, what you've tried yourself so far and what problems you're running into. – engelen Jun 25 '14 at 13:53
  • Well you have 'post_type'=> 'Media'` which tells your tag.php to only show posts under the post type Media. What are you trying to show on tag.php? – Howdy_McGee Jun 25 '14 at 14:06
  • Greetings both, I have tried to make it more clear in my post. thanks for taking your time! – Sigils Jun 26 '14 at 8:06

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.