php - Get tag posts wordpress -


i've written code automatically creates posts , adds tag them. can see tags in 'all posts' admin panel , can click on posts 'tag' link posts tags.

here code:

<?php $tag_id= single_tag_title();                     $args = array(                         'post_type' => 'post',                         'tag_id'    =>  $tag_id,                         'posts_per_page' => 10,                         'order'          =>'asc'                     );                     $posts = get_posts( $args );                     var_dump($args );                     foreach ( $posts $post ) {                         ?> 

can me tag posts? thank you.

create new file (tag.php) in wp-content/themes/yourthemefolder/ , put below code in it.

<?php get_header();  $tag = single_tag_title('', false); echo '<h1>tag: ' . $tag . '</h1>';  $args = array(     'post_type' => 'post',     'taxonomy' => $tag,     'terms' => $tag,     'posts_per_page' => 10,     'order' => 'asc' ); $postslist = get_posts($args);  foreach ($postslist $post) :     setup_postdata($post);     ?>     <div id="post">         <h2>post title:<?php the_title(); ?></h2>          <p><?php the_content(); ?></p>     </div> <?php endforeach;  get_footer(); ?> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -