Try using $query->get()
instead of get_query_var()
.
function my_orderby_filter($orderby, &$query){
global $wpdb;
//figure out whether you want to change the order
if ($query->get("post_type") == "portfolio") {
return "$wpdb->posts.post_title ASC";
}
return $orderby;
}
Alternatively, you can use this one, which filters the query via the pre_get_posts
hook.
add_action( 'pre_get_posts', 'my_orderby_filter2' );
function my_orderby_filter2( $query ) {
if ( 'portfolio' === $query->get( 'post_type' ) ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}