• Resolved goldmember

    (@goldmember)


    i’m using a PHP Code widget to list upcoming events on my homepage. how do i change the order in which they appear? current the most recent post appears at the top, but i want to reverse it so the most recent post appears at the bottom. how do i do this? thanks in advance!

    <?php
    //display 5 posts for category ID 3
    $taxonomy = 'category';
    $taxargs ='include=3';
    $terms = get_terms( $taxonomy, $taxargs );
    foreach( $terms as $term )  {
      $args=array(
        'category__in' => array($term->term_id),
        'showposts'=> 5,
        'caller_get_posts'=>1
       );
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo '';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        endwhile;
      } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().
    } //foreach
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Add ‘order’ => ‘ASC’, in your $args array

    Thread Starter goldmember

    (@goldmember)

    i tried it like this and got a bunch of errors:
    $taxargs ='include=3'; 'order' => 'ASC'

    then i tried it like this and it had no effect:
    $taxargs ='include=3'; 'order=ASC';

    i know little about php so i’m probably formatting it wrong. please advise how to correct? thanks!

    Like this:

    $args=array(
        'category__in' => array($term->term_id),
        'showposts'=> 5,
        'caller_get_posts'=>1,
        'order' => 'ASC'
       );

    If this works, please mark this topic ‘Resolved’.

    Thread Starter goldmember

    (@goldmember)

    it did not work. i got an error.

    OK – so what was the error?

    Thread Starter goldmember

    (@goldmember)

    actually it works. i had pasted it in incorrectly. thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘changing post order in widget’ is closed to new replies.