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
Post a Comment