• Resolved game123

    (@game123)


    can someone help me please i am trying to use category list orderby date or most recent category list in my index page but can’t find solution anywhere ???

    What do I do?

    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    // get 20 latest posts, display the categories used on those posts
    $cat_array = array();
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 20,
      '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 20 latest posts</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().
    ?>
    Thread Starter game123

    (@game123)

    thank you thank you MichaelH 🙂

    my problem is solved

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘category orderby date’ is closed to new replies.