WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show category name that have today post? (3 posts)

  1. technocode
    Member
    Posted 3 years ago #

    Hello..

    How to show all category name that have today post?

    Thank you..

  2. MichaelH
    Member
    Posted 3 years ago #

    <?php
    // display the categories used on today's posts
    $this_year = date('Y');
    $this_month = date('m');
    $this_day = date('d');
    $args=array(
      'year' => $this_year,
      'monthnum' => $this_month,
      'day' => $this_day,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
      );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post();
        $cat_args=array('orderby' => 'none');
        $cats = wp_get_post_terms( $post->ID , 'category', $cat_args);
        foreach($cats as $cat) {
          $cat_array[$cat->term_id] = $cat->term_id;
        }
      endwhile;
    }
    if ($cat_array) {
      echo '<p>List of categories used on posts for '.$this_year.$this_month.$this_day.'</p>';
      foreach($cat_array as $cat) {
        $category = get_term_by('ID',$cat, 'category');
        echo '<p><a href="' . esc_attr(get_term_link($category, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a><p> ';
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. technocode
    Member
    Posted 3 years ago #

    Thank you so much MichaelH..

    You are the man.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags