• Resolved ozpoker

    (@ozpoker)


    Would anyone know what code I can use to sort my custom taxonomy template by anything other than the defaults?

    example:
    I have set up a custom post type “type” and a custom taxonomy “year” which has sub-categories : 2001, 2002, 2003, 2004, 2004 etc.

    I have this code in the template head which grabs the taxonomy sub-category name

    <?php    global $wp_query;
       		 $term = $wp_query->get_queried_object();
       		 $title = $term->name;
    ?>

    it’s pretty simple to display all “types” assigned to each year – it is just http://www.mysite.com/year/1995

    Those posts are handled by the template taxonomy-year.php

    But the posts arrive at the template and the order is still in the default post order – presumably postID.

    They are displayed by the default loop
    <?php if (have_posts()):while (have_posts()) : the_post(); ?>

    Have set up many custom meta fields I could sort by but as the posts already arrived at the template “queried” it doesn’t seem to make sense to “query” them yet again.

    Can anyone help? I would rather not use plugins please.

Viewing 7 replies - 1 through 7 (of 7 total)
  • It could be as simple as adding:

    <?php query_posts($query_string . '&orderby=date&order=ASC'); ?>

    just before the

    <?php if (have_posts()):while (have_posts()) : the_post(); ?>

    Thread Starter ozpoker

    (@ozpoker)

    Hi – i am using this

    <?php
    		$customtypeargs = array(
      			 'meta_key' => 'group_race_date',
      			 'orderby' => 'meta_value',
    			'post_type' => 'result',
    		);
    	?>
    			<?php query_posts($customtypeargs); ?>
    			<?php if (have_posts()):while (have_posts()) : the_post(); ?>

    which is a derivation of your solution

    But the query is returning all posts – not just the ones from the custom taxonomy “year”

    Any ideas?

    Thread Starter ozpoker

    (@ozpoker)

    Don’t worry – worked it out

    need to add the custom taxonomy to the query with the value got from the first global query, in this case ‘group_year’ => $title,

    <?php
    		$customtypeargs = array(
      			'meta_key' => 'group_race_date',
      			'orderby' => 'meta_value',
    			'order' =>  'DESC',
    			'post_type' => 'result',
    			'group_year' => $title,
    		);
    	?>

    Hope this helps someone else as I’ve spent days on it

    Thread Starter ozpoker

    (@ozpoker)

    Okay went too early – this is not resolved

    MichaelH – can you help please.

    By using this :

    <?php
    		$customtypeargs = array(
      			'meta_key' => 'group_race_date',
      			'orderby' => 'meta_value',
    			'order' =>  'DESC',
    			'post_type' => 'result',
    			'group_year' => $title,
    		);
    	?>
    			<?php query_posts($customtypeargs); ?>
    			<?php if (have_posts()):while (have_posts()) : the_post(); ?>

    It merely reloads the last 10 posts in that custom taxonomy archive every time and I have lost all my pagination in the archive

    so page2 and page3 etc are not loading the “next” 10 posts just showing the first 10 again and again.

    Thread Starter ozpoker

    (@ozpoker)

    here’s the full code for taxonomy-group_year.php

    would love some help

    the idea was just to sort the custom archive by a custom field “date”

    That works but I have lost all pagination

    http://wordpress.pastebin.ca/1891756

    Thread Starter ozpoker

    (@ozpoker)

    solved it myself by adding

    'paged' => $paged,
    'posts_per_page' => 20,

    to the $customtypeargs array

    Michael H, I did this on my custom post archive page:

    <?php query_posts($query_string . '&orderby=date&order=ASC'); ?>

    And when I add that I get Not found. Without it it’s fine just not sorted properly. is $query_string correct?

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

The topic ‘sort custom taxonomy archive’ is closed to new replies.