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' );
}
}
Related Posts:
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Custom Post type sort order not working in the admin area
- Combining sorted and random CPT
- Wp_query: sort by PHP variable
- Custom post type order by post_title
- Wp Query sort order from custom MetaBox
- Using Orderby and meta_value to order natural/alphanumerical
- How to sort custom post’s category by id from the theme’s function.php?
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Custom post type – order field
- Make custom column sortable
- Displaying a custom post type alphabetically
- Order by & include array by specific post ids
- Drag n Drop Post Order for multiple Custom Post Types
- Custom sortable columns ordered by meta-value?
- WordPress post sorting with AJAX
- Sorting a query by custom field date
- Ordering Posts List By Taxonomy Terms?
- Column sorting with emtpy meta values
- Number of pages – multiple (custom) post types
- how to sort post in admin column by recently
- How to sort a table of custom posts by column containing custom field
- List upcoming events, ordered by date in a custom field
- How to Sort Custom Field Admin Column by Date
- WP_Query post at custom position
- Sort custom post types by last name in the backend
- Re-order posts in query after
- Sort Posts Best Practice
- Custom Post Type sorted by Title
- Display custom post types with custom date field value (before today) & order by custom date field
- How do I sort a custom post type admin column using two meta keys?
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- How to query different post types in specific order?
- How to quickly reorder posts in the admin panel that will persist for the wp-api
- Custom post type ‘orderby’ => ‘meta_value’ not working
- How to rank custom post type from score points
- How do I make a custom taxonomy for a CPT appear inbetween title and editor boxes?
- Show listings from Impress Listing plugin in random order using taxonomy and terms
- I did group my search results by post type, but how can i give each of them its own order?
- Ordering posts in Search & taxonomy by post_meta
- Default sort on admin columns with meta date hides draft posts with empty date value
- Categories sorting
- Allow user to set custom order to a list of custom taxonomies?
- Crafting WP_Query array, sort by date
- Sort CPT archive by order prevents sorting in admin
- WooCommerce sort products by the actual product width(not the shipping width)
- How to order and group custom post type posts by year and month
- Order Custom Post Type by Custom Field Value
- Sort and filter custom post type posts by custom taxonomy
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Get the taxonomy of a post hierarchically
- Change sort order when using ‘orderby’ => ‘type’
- Ordering custom post type by multiple custom fields
- Order by custom field meta_key date and then by custom file meta_key number
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Ascending Order is not Working in Custom Post Type Listining
- sort post types by amount of views
- $wpdb->get_col and ORDER BY?
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Sort custom post type by most current date picker
- WP_Query not resetting after wp_reset_postdata
- Sort results without WP_QUERY?
- Make a custom column sortable by a value from a different custom post type
- sort by name (slug) custom post type
- Sorting custom post types in edit.php : Post disappear
- show most viewed posts of last days by link?
- How can I sort the order of multiple custom field values in a custom post type?
- Sorting the Loop by Taxonomy Value
- Display Parent-Child Posts in specific order by comparing IDs in array
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- Orderby if between two meta fields
- Sort custom post type by custom datepicker instead of filtering
- Display custom posts, ordered by most commented, without duplicates
- How to sort by multiple values in a nested WP_Query
- SEARCH QUERIES – REVERSE OUTPUT
- How to order multiple custom post types with same taxonomy by date
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- week days sorting based on starting day
- Group/list/sort custom post type posts by date in tabs from acf datepicker field
- Grouping and paging CPT events by month with custom field date
- WP Query with multiple post types ordered by custom meta date then published date
- Orderby modified only for specific post types
- Ordering Posts List By Taxonomy Terms?
- Custom post type taxonomy not sorting correctly
- shortcode order for event custom post type
- Order Custom Posts by Several Fields
- How do I sort post listing by child post count?
- Make custom post type column sortable
- 404 on Pages for Custom Post Type & Query_Posts
- Order custom post type is beign ignored
- Test if a Category contains certain Custom Post Types
- How to order different custom post type in category or tag template page?
- WP_query orderby not working after WP4.0 update [closed]
- Query order by meta value force specific tag first
- Sort CPT by taxonomy AND THEN by custom field
- Custom order of CPT posts by title, in wp-admin area by default
- Sorting by Title for Post Archive Categories for Custom Post Type
- Meta query sort order is lexigraphical instead of numeric
- Query multiple post types – Order by type and post title title