Top tags with minimum number of posts

I'm getting the most used tags in the 1 day interval and everything works fine but how do I add the limitation to g

I'm getting the most used tags in the 1 day interval and everything works fine but how do I add the limitation to get tags with at least 5 posts and order them by counting?

Actual code:

$term_ids = $wpdb->get_col("
    SELECT term_id FROM $wpdb->term_taxonomy
    INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
    INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
    WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) <= $wpdb->posts.post_date"            
);

$tags = get_tags(array(
    'orderby' => 'count',
    'order'   => 'DESC',
    'number'  => 10,
    'include' => $term_ids,
));

foreach ( (array) $tags as $tag ) {
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
}

Thanks in advance!

I'm getting the most used tags in the 1 day interval and everything works fine but how do I add the limitation to get tags with at least 5 posts and order them by counting?

Actual code:

$term_ids = $wpdb->get_col("
    SELECT term_id FROM $wpdb->term_taxonomy
    INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
    INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
    WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) <= $wpdb->posts.post_date"            
);

$tags = get_tags(array(
    'orderby' => 'count',
    'order'   => 'DESC',
    'number'  => 10,
    'include' => $term_ids,
));

foreach ( (array) $tags as $tag ) {
    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
}

Thanks in advance!

Share Improve this question edited May 30, 2019 at 21:27 Alex asked May 30, 2019 at 20:24 AlexAlex 155 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found a solution!:

$term_ids = $wpdb->get_col("
    SELECT term_id FROM $wpdb->term_taxonomy
    INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
    INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
    WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) <= $wpdb->posts.post_date"            
);

$tags = get_tags(array(
    'orderby' => 'count',
    'order'   => 'DESC',
    'number'  => '10', // <-- maximum number of tags
    'include' => $term_ids,
    'fields'  => 'ids'
));

foreach($tags as $tag) {                
    $term = get_term_by('id', $tag, 'post_tag');
    if ($term->count < 5) { // <-- minimum number of posts              
        $index = array_search($term->term_id, $tags);
        unset($tags[$index]);                   
    }               
}

foreach ( (array) $tags as $tag_result ) {
    $term = get_term_by('id', $tag_result, 'post_tag');
    echo '<li><a href="' . get_tag_link ($term->term_id) . '" rel="tag">' . $term->name . '</a></li>';
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745446749a4628081.html

相关推荐

  • Top tags with minimum number of posts

    I'm getting the most used tags in the 1 day interval and everything works fine but how do I add the limitation to g

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信