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?
- Admin custom post ordering
- Adding ‘menu order’ column to custom post type admin screen
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Custom post type – order field
- How do I set the default admin sort order for a custom post type to a custom column?
- Make custom column sortable
- Using meta_query, how can i filter by a custom field and order by another one?
- group search results by post type?
- register_post_type sort order by title by default
- Displaying a custom post type alphabetically
- Order by & include array by specific post ids
- Drag n Drop Post Order for multiple Custom Post Types
- Sort custom post type list table by display name of a user id stored as post meta value
- Sortable column containing numeric values for Custom Post Type at WordPress Backend
- $wpdb->get_col and ORDER BY?
- Custom Post Type page sorts differently on different environments
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Sort custom post type by most current date picker
- WP_Query of custom post type sorted by meta_key has unexpected results
- WP_Query not resetting after wp_reset_postdata
- Creating a “glossary” of WordPress posts of a specific post type
- Sort results without WP_QUERY?
- Make a custom column sortable by a value from a different custom post type
- Post ordering not working with custom field
- Filtered by a custom field, ordered by another
- orderby parameter not working in custom query
- sort by name (slug) custom post type
- Adding Page Ordering to a Custom Page Type
- Sort column on meta key and meta value
- Displaying Portfolio Filter by Category Order (alphabetically)
- Sorting custom post types in edit.php : Post disappear
- show most viewed posts of last days by link?
- Custom loop request based on custom field
- Changing WordPress sort order for returned child pages
- What’s an easy way of sorting custom post types manually?
- How can I sort the order of multiple custom field values in a custom post type?
- Sorting the Loop by Taxonomy Value
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Order posts by taxonomy terms
- wp rest api orderby field in a custom table
- Sort custom posts by date and then by taxonomy
- 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?
- Custom post type sortable columns when column value is from a custom database value
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to order taxonomy terms by most recent post?
- 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
- order custom post type posts by custom date
- How to sort post category using its Description
- 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)
- sorting in wp query based on custom field value
- week days sorting based on starting day
- What’s the most efficient way to get two queries based on an if statement?
- 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
- Show first posts with custom field not empty and order all by title
- 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 order when using OR relation
- Help ordering custom query by Title, Ascending
- Custom post type taxonomy not sorting correctly
- shortcode order for event custom post type
- How to display custom post type ordered by a custom field date
- Order Custom Posts by Several Fields
- Custom Post Type Order Index Loop
- show previous/next post orderer by title in custom post types
- Ordering custom post type by custom field without a title
- How do I sort post listing by child post count?
- Make custom post type column sortable
- Create custom post order (with custom post type meta)
- 404 on Pages for Custom Post Type & Query_Posts
- sort custom post type by display name
- How can I sort posts ascending by post title for a specific post type, but on a category archive template?
- Allow admin to determine the order of queries?
- Posts 2 Posts: query connected — orderby problem
- 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
- Order Wp Query by earliest of 3 dates meta query
- 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