• I don’t know what I’m doing wrong, but sorting posts in a category to be ascending doesn’t seem to work.

    Here are my snippets:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      query_posts(array('category__in' => array($cat), 'posts_per_page' => -1, 'orderby' => 'date',
         'order' => 'ASC'));
    }
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php
       $args = array(
         'category_name' => 'Category',
         'posts_per_page' => 1,
         'order_by' => 'date',
         'order' => 'ASC'
    );
    $args['order'] = 'ASC';
    $my_query = new WP_Query($args);
    while ($my_query->have_posts()) {
      $my_query->the_post(); ?>
      <a href="<?php the_permalink(); ?>" title="Latest post">Latest post</a>
      <?php }
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    try this 1nstead of the 1st snippet:

    <?php
    foreach( get_categories() as $cat_id ) {
      $args=array(
        'cat' => $cat_id,
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => 2,
        'caller_get_posts'=> 1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of Posts for category '. $cat_id;
        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
        //the_content();  //or the_excerpt{};
        endwhile;
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter EntarteteMuzak

    (@entartetemuzak)

    No, sorry that doesn’t work.
    Catchable fatal error: Object of class stdClass could not be converted to string in /storage/content/26/129226/palaistra.org/public_html/wp-includes/query.php on line 1420

    i think code below:
    $cat = get_query_var(‘cat’);
    query_posts(array(‘category__in’ => array($cat), ‘posts_per_page’ => -1, ‘orderby’ => ‘date’,
    ‘order’ => ‘ASC’));
    have problem parameter ‘category__in’ => array($cat) or ‘orderby’ => ‘date’

    code second:
    foreach( get_categories() as $cat_id ) {
    $args=array(
    ‘cat’ => $cat_id,
    ‘post_type’ => ‘post’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => 2,
    ‘caller_get_posts’=> 1
    );
    }
    have problem parameter ‘cat’ => $cat_id ($cat_id is array)

    give me question:
    do you need any posts ?
    can i help you?
    sorry, my english is very bad, not describle good

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Ascending posts not working?’ is closed to new replies.