Horje
Archive page renders results alphabetically - Wordpress Solution
[Solved] - Archive page renders results alphabetically - Wordpress Solution
Try following codes
For some reason my archive page is rendering both taxonomy menu items and the taxonomy results alphabetically and I can't figure out why (or when it happened). See the page at http://seontario.org/resources/. The menu on the left should be displaying a taxonomy menu, with proper hierarchy, while the post list on the right is showing the posts correctly within their taxonomies, but the hierarchy of the taxonomies has been lost (general, legal structures, procurement and social finance policy should all be under 'policy'). The archive-resource.php is here: [[LINK href="http://pastebin.com/gexc7u3x"]]http://pastebin.com/gexc7u3x[[/LINK]] There's a function to change the order of another archive to alphabetical, but even after deleting it this page isn't corrected. That function is as follows:

/* 
Change the number of posts in the Projects Archive
*/

function seo_modify_num_posts_for_projects($query)
{
  if ($query->is_post_type_archive('seo_project') && $query->is_main_query() && !is_admin()) {
      $query->set('posts_per_page', 100);
      $query->set('orderby', 'title');        
      $query->set('order', 'ASC');
	}
}
add_action('pre_get_posts', 'seo_modify_num_posts_for_projects');
CW

Solution - 1

Hi Christopher Is there a reason you don't sort the results in the WP_Query? I'm assuming that this is the query you want to sort:

$resourcequery = new WP_Query( array(
         'post_type' => 'seo_resource',
	'tax_query' => array(
		array(
			'taxonomy' => '$taxonomy',
			'field' => 'slug',
			'terms' => '$term->slug'
		)
	),
        'posts_per_page' => 100,
        'orderby' => 'title', 
        'order' => 'ASC'
 ));
Also, you should put a wp_reset_query at the end of the all the loops. It looks like you don't need it, but it's always good practice to put it in for non-loop queries. JC

Date: 2022-10-21 04:58:59
Category: Wordpress
More for You