My custom 'Home' page is set to sort my custom posts via the custom date field with this (updated to be custom named) code in functions.php:
// sort order for home page
add_action('wp', 'wwgo_check_page');
function wwgo_check_page () {
if (is_page()) {
add_filter('get_previous_post_sort', 'sort_it');
add_filter('get_next_post_sort', 'sort_it');
add_filter('posts_orderby', 'sort_it' );
add_filter('posts_join', 'join_it' );
add_filter('posts_where', 'where_it' );
function sort_it () {
global $wpdb;
return " $wpdb->postmeta.meta_value ASC ";
}
function join_it( $join ) {
global $wpdb;
$join .= " LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id) ";
return $join;
}
function where_it( $where ) {
global $wpdb;
$where .= "AND $wpdb->postmeta.meta_key = 'deadline' ";
return $where;
}
}
}
Which is dandy and simple. Now. I want this to work across the whole site. I want posts on archive pages, categories etc to be sorted first by the custom date field.
Any ideas?
I have tried changing the 'if
' to is_archive()
but that had no effect. I tried <! is_single()>
too.
I'm sure it should be something simple. But I'm new to php and thus clueless.
Here is the site, where you can see the home page is nicely sorted, but if you click 'poetry' (the only one with a few posts), sorting doesn't work.
Any suggestions will be met with much joy.
Thank You Kindly.
josh_
to avoid naming colisions.