How can I re-sort results of a query after filtering
-
I have a custom post type of ‘inductees’ and I need to list out these inductees in a ‘last name, first name’ order. The problem is that the titles for each of the inductees is ‘first name last name’. Well, I have a filter working on the query, but the inductee order remains based on the first word (first name) of the inductees. How can I sort the data based on the filtered post titles?
Here is the code I am working from:
<?php global $wp_query; $inductees = query_posts( array( 'post_type' => 'inductee', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); function sort_inductee_names( $golfer ) { $golfer_array = explode( ' ', $golfer ); $golfer_last_name = array_pop( $golfer_array ); $golfer = $golfer_last_name . ', ' . ( join( ' ', $golfer_array ) ); return $golfer; } add_filter( the_title, sort_inductee_names, 1 ); ?>
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘How can I re-sort results of a query after filtering’ is closed to new replies.