wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=3&post_type=post
这是我点击后端类别名称时的链接:
$args = array( 'post_type' => 'post' , 'orderby' => 'menu_order' , 'order' => 'ASC' , 'posts_per_page' => -1);
通过使用此功能,我想显示该特定类别tag_id=3
的帖子。我怎么能这样做?
这是完整的代码:
<div class="gallery">
<?php
$i = 1;
$args = array( 'post_type' => 'post' , 'orderby' => 'menu_order' , 'order' => 'ASC' , 'tag_id'=> 3 , 'posts_per_page' => -1);
$wp_query = new WP_Query($args);
$count = $wp_query->found_posts;
while ( have_posts() ) : the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<a href="<?php echo $image[0]; ?>" title="<?php the_title();?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('thumbnail'); }?></a>
<?php $i++; endwhile;?>
</div>
答案 0 :(得分:2)
您可以使用WP_Query通过tag_id
显示帖子尝试这样:
$args = array( 'post_type' => 'post' , 'orderby' => 'menu_order' , 'order' => 'ASC' , 'posts_per_page' => -1,'tag_id'=> 3);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
答案 1 :(得分:0)
global $wpdb;
$Qu = $wpdb->get_results("select * from wp_posts where post_title='somthing' and 'post_type' => 'post'");
$ID = $Qu[0]->ID;
$Qu1 = $wpdb->get_results("select * from wp_term_relationships where object_id='".$ID."'");
$ID1 = $Qu1[0]->term_taxonomy_id;
$Qu12 = $wpdb->get_results("select * from wp_term_taxonomy where object_id='".$ID1."'");
echo $ID1 = $Qu12[0]->term_id;