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?
- Custom post type – order field
- Make custom column sortable
- group search results by post type?
- 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?
- Sort Order for a Custom Query in a Post Type Archive Not Working
- How to order adjacent posts (prev / next) by custom field value?
- Ordering posts by custom taxonomy in admin area
- Sorting a query by custom field date
- Ordering Posts List By Taxonomy Terms?
- 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
- Alphabetical sorting of custom post type – one letter per page
- 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
- Sort by two dates. Default entry date and custom field if present
- Display custom post types with custom date field value (before today) & order by custom date field
- Custom Post Type order by modified date and custom meta field issue
- 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?
- Sort admin area by custom Event Date field
- How to quickly reorder posts in the admin panel that will persist for the wp-api
- 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?
- Sorting multiple custom post types without a meta key/value pair by sort order
- Show listings from Impress Listing plugin in random order using taxonomy and terms
- Rewrite and custom post type: order by custom field not working
- Previous/Next Link by Meta Value in CPT
- 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
- Order Custom Post Type by Custom Field Value
- Sort and filter custom post type posts by custom taxonomy
- WordPress posts page for customer filtering and sorting along with category filter
- 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
- 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
- Filtered by a custom field, ordered by another
- orderby parameter not working in custom query
- 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?
- Custom loop request based on custom field
- How can I sort the order of multiple custom field values in a custom post type?
- Sorting the Loop by Taxonomy Value
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Orderby if between two meta fields
- Sort custom post type by custom datepicker instead of filtering
- How to sort by multiple values in a nested WP_Query
- 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
- 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
- Orderby modified only for specific post types
- Ordering Posts List By Taxonomy Terms?
- Help ordering custom query by Title, Ascending
- 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
- Ordering custom post type by custom field without a title
- Make custom post type column sortable
- Create custom post order (with custom post type meta)
- 404 on Pages for Custom Post Type & Query_Posts
- 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?
- Order Wp Query by earliest of 3 dates meta query
- Custom order of CPT posts by title, in wp-admin area by default