I found a snippet, which order all posts alphabetically. I wonder if is there a way to make it working just for one post-type? I have some custom post type in my website, and i want one of them to be ordered alphabetically, but the rest by date.
I changed filter_next_post_sort
and fiter_previous_post_sort
like this:
function filter_next_post_sort($sort) {
if (get_post_type($post) == 'MyCustomPostType') {
$sort = "ORDER BY p.post_title ASC LIMIT 1";
}
else{
$sort = "ORDER BY p.post_date ASC LIMIT 1";
}
return $sort;
}
I hope it’s good like that.
But i need to change filter_next_post_where
and filter_previous_post_where
as well, but i don’t find the right way.
Now they look like this:
function filter_next_post_where($where) {
global $post, $wpdb;
return $wpdb->prepare("WHERE p.post_title > '%s' AND p.post_type="". get_post_type($post)."" AND p.post_status="publish"",$post->post_title);
}
function filter_previous_post_where($where) {
global $post, $wpdb;
return $wpdb->prepare("WHERE p.post_title < '%s' AND p.post_type="". get_post_type($post)."" AND p.post_status="publish"",$post->post_title);
}
Any suggestion, what to change? Thanks!
EDITED: I tried this, but it’s not working:
function filter_next_post_where($where) {
global $post, $wpdb;
if (get_post_type($post) == 'szinesz') {
return $wpdb->prepare("WHERE p.post_title > '%s' AND p.post_type="". get_post_type($post)."" AND p.post_status="publish"",$post->post_title);
}
else{
return $wpdb->prepare("WHERE p.post_date > '%s' AND p.post_type="". get_post_type($post)."" AND p.post_status="publish"",$post->post_title);
}
}
Oh, and i use WP 4.1.1.