Because price
is not a post table column (I’m assuming it’s a post meta field), you need to extend the query & order by meta_value_num
instead:
case 'title':
if ( ! $meta_query = $vars->get( 'meta_query' ) )
$meta_query = array();
$meta_query[] = array(
'compare' => '!=',
'value' => '',
'key' => 'price', /* This should be the name of your meta field that stores price */
);
$vars->set( 'meta_query', $meta_query );
$orderby = 'meta_value_num';
$order="ASC";
break;
Related Posts:
- Order by two meta values – one is a number and the other is text
- Problem with meta_value order after update
- Sort on meta value but include posts that don’t have one
- Using Orderby and meta_value_num to order numbers first then strings
- multiple orderby in pre_get_posts action
- Sort Order for a Custom Query in a Post Type Archive Not Working
- get_the_terms in descending alphabetical order
- next and previous post link ordered alphabetically
- Order posts by meta_value even if meta_key is not filled
- Order by first name
- How to alter query order direction using $query->set(‘order’, ‘ASC’); inside a pre_get_posts filter?
- Order by custom field date with ASC order
- the_tags() : display the tags by the order they are typed in in the backend, not alphabetically
- Sorting Attributes order when using get_the_terms
- How to order posts by meta value?
- How Do I Order Posts by Modified Date? [duplicate]
- Orderby Post Views
- How to order posts (woocommerce products) alphabetically but ignore certain words, eg ‘The’ and ‘An’
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to order posts by alphabet with numbers at the end
- Best Plugin to Reorder Post Types
- Ordering system through WordPress
- Issue with multiple orderby values
- get_query_var returns wrong default value
- Use pre_get_posts to sort meta_key by an array of values
- Show first the posts from 1 specific tag
- AJAX pagination offset returns same post on adjacent pages
- Order posts by price
- All, published and pending order
- How to orderby multiple meta fields if some fields are empty
- get_adjacent_post() returning weird results
- Get_Users Orderby Page
- Sort order of next/prev sibling page
- Order char by post title
- Why does pre_get_posts() return “date” as the orderby parameter for every sortable column?
- next_post_link and previous_post_link order not working properly
- query pages by a childs publish date
- Custom order for Mysql array
- WordPress Screwing Up ‘orderby’ => ‘meta_value_num’ in ‘pre_get_posts’
- List most recently added posts (with a twist)
- Check post_date in pre_get_posts
- pre_get_posts shows posts in random order sometimes
- Featured-Content/Featured Posts With Random Order
- Orderby in Query Posts affected by operating system?
- Ordering posts by title containing numbers
- Stylesheet Enqueue Order and Best Practices
- Sortable Custom Columns not sorting correct
- wp_list_pages sort order by top nav menu order and child of
- How to display taxonomy terms the way they are hierarchical
- wp_list_categories() by alphabet? (ex. only category titles that start with “A”) [closed]
- How can I use ‘orderby’ => ‘meta_value_num’ to order by the numerical value even if the value starts with a word?
- Order by ASC, DESC, Title, Date from URL on custom page template post
- Offset posts with random order
- view subcategories order by id
- Sort query output on taxonomy term archive by post type using pre_get_posts
- ASC and DESC separately from orderby
- Order WP_Query by The Order of an Array in Tax_Query
- struggling to order by title
- Last post sorting get_categories
- Sort products by Sale price and stock status
- Sort by DESC works, ASC doesn’t?
- Shop sends Mail with order cancellation
- List of terms in alphabetical order under the respective initial letter and within columns
- update_post_meta saves data but does not show in Order backend
- Changing cache update rate
- how to complete order status automatically after paypal payment received
- Order management including recurring orders on woocommerce
- Orderby Title not working
- Sort loop by title doesn’t sort single digits like human would
- Using Orderby and meta_value to order natural/alphanumerical
- Loop random posts and display odd and even based on two alternating meta values?
- Sort posts by meta value with get method
- Order posts by more than one variable (meta_key and publish date AND time)
- How to order custom user list columns by datetime?
- Creating a post that contains a list of other posts like a table of contents
- Changing posts order on a page
- Ordering Subcategories
- How to order posts by parents?
- single post navigation order (NOT chronological)
- Random order of posts on each request
- Order by meta values
- How can I make have_posts() return posts ordered DESC by id?
- Add post order like page order
- Woocommerce Pre Orders view order link wrong [closed]
- How to make WordPress orderby work with post_excerpt column?
- Orderby with menu_order and title
- Sort wordpress posts by facebook likes [closed]
- Sorting by date not working?
- WP_Query – Order results by meta value
- How to only display posts whose meta_value field is not empty?
- Adding ‘menu order’ column to custom post type admin screen
- Is it possible to paginate posts correctly that are random ordered?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Custom post type – order field
- Max length of meta_value
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to Change Order of Posts in Admin?
- WP_Query orderby date not working
- Get current menu_order