• Resolved earthmanweb

    (@earthmanweb)


    After using wp_category_dropdown to create a jumplist of terms from a custom taxonomy, I am using query_posts to retrieve custom posts (jobs) based on the selected term id (job-category) in the GET vars…

    // convert the term_id in the GET var to a slug for query_posts
    if($_GET['term_id']):
         $term = get_term_by( 'id', $_GET['term_id'], 'job-category');
      if($term->slug){
         query_posts( 'job-category='.$term->slug.'&post_status=publish&orderby=date&order=DESC' );
         //display text below
         $filter_text = '<h3>Displaying Jobs in category: '.$term->name.'</h3>';
      } else {
         query_posts( 'post_type=jobs&post_status=publish&orderby=date&order=DESC');
    }
    else: // no queryvar set
      query_posts( 'post_type=jobs&post_status=publish&orderby=date&order=DESC');
    endif;

    The code works fine, except the problem I have is that the posts are not ordering by date, as specified. I even used the following code to check the query:

    echo "Query:<pre>";
    print_r($wp_query->query);
    echo "</pre>";

    and it outputs the following:
    job-category=administrative-clerical-support&post_status=publish&orderby=date&order=DESC

    Anyone have any idea why this isn’t working, please, or if it is a bug in 3.0? I’m completely stumped…

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • At least at 3.0 beta-2-14697 I’m not seeing that problem with my test data with a post_type of books and a custom taxonomy of genre. And changing orderby to ASC or DESC returns correct results.

    <?php
    $args=array(
      'genre' => 'mystery',
      'post_type' => 'book',
      'orderby' => 'date',
      'order' => 'DESC',
      '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() ) {
      echo 'List of Posts';
      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;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter earthmanweb

    (@earthmanweb)

    Hi Michael,

    I am using query_posts, not the code you are using.

    I am not sure how your posted code relates to my question…?

    I can try your code instead of query_posts, but that doesn’t really solve the problem, being the query_post issue.

    Thread Starter earthmanweb

    (@earthmanweb)

    Hi Michael,

    I tested your code and it was not working either.

    I tracked it down to a conflict with the “postmash” plugin…

    Thanks for your time!

    Hey Michael, thanks for the tip!

    I was working on :

    $args = array(
    'post_type' => 'product',
    'taxonomy' => 'prodcat',
    'term' => 'term name',
    'nopaging'=>true,
    'orderby'=>'title',
    'order'=>'ASC',
    );
    query_posts($args);

    and it didn’t seem to want to sort by title properly, but using your version instead it worked brilliantly! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query posts with custom term not ordering posts’ is closed to new replies.