Skip to main content
Fix formatting of function, and update the action to use the correct function
Source Link

I've assumed that since the posts have already been returned then I should use 'query_posts' to alter the order of the posts.

That assumption is wrong. You should pretty much never use query_posts.

Use a filter on pre_get_posts.

function pregp_wpse_108235( $qry ) {
    if ( $qry->is_main_query() && $qry->is_tax() ) {
        $qry->set( 'order', 'ASC' );
    }
}
add_action( 'pre_get_posts','pregp_archive_ppp_wpse_108235' 'pregp_wpse_108235' );

But that completely destroys the original list of returned posts and replaces it with regular posts.

Yes, what you did would return the normal post index. You did not supply any of the taxonomy arguments, but as query_posts is the wrong way to go anyway there is no point in worrying about that.

I've assumed that since the posts have already been returned then I should use 'query_posts' to alter the order of the posts.

That assumption is wrong. You should pretty much never use query_posts.

Use a filter on pre_get_posts.

function pregp_wpse_108235($qry) {
  if ($qry->is_main_query() && $qry->is_tax()) {
      $qry->set('order','ASC');
  }
}
add_action('pre_get_posts','pregp_archive_ppp_wpse_108235');

But that completely destroys the original list of returned posts and replaces it with regular posts.

Yes, what you did would return the normal post index. You did not supply any of the taxonomy arguments, but as query_posts is the wrong way to go anyway there is no point in worrying about that.

I've assumed that since the posts have already been returned then I should use 'query_posts' to alter the order of the posts.

That assumption is wrong. You should pretty much never use query_posts.

Use a filter on pre_get_posts.

function pregp_wpse_108235( $qry ) {
    if ( $qry->is_main_query() && $qry->is_tax() ) {
        $qry->set( 'order', 'ASC' );
    }
}
add_action( 'pre_get_posts', 'pregp_wpse_108235' );

But that completely destroys the original list of returned posts and replaces it with regular posts.

Yes, what you did would return the normal post index. You did not supply any of the taxonomy arguments, but as query_posts is the wrong way to go anyway there is no point in worrying about that.

Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

I've assumed that since the posts have already been returned then I should use 'query_posts' to alter the order of the posts.

That assumption is wrong. You should pretty much never use query_posts.

Use a filter on pre_get_posts.

function pregp_wpse_108235($qry) {
  if ($qry->is_main_query() && $qry->is_tax()) {
      $qry->set('order','ASC');
  }
}
add_action('pre_get_posts','pregp_archive_ppp_wpse_108235');

But that completely destroys the original list of returned posts and replaces it with regular posts.

Yes, what you did would return the normal post index. You did not supply any of the taxonomy arguments, but as query_posts is the wrong way to go anyway there is no point in worrying about that.