i assume its exclusive to either sort by title $_GET['sort_title']
OR sort by custom field ( but not necessarily) and you that you pass $_GET['sort_price']
. if neither are present, “title” is default.
with that in mind, check both values
if( isset($_GET['sort_title']) ) {
$sort_by = $_GET['sort_title'];
//orderby can accept multiple values
}
elseif ( isset($_GET['sort_price']) ) {
$sort_by = 'meta_value';
$args["meta_key"] = 'price';
}
else { $sort_by = "title";
if so, don’t forget to change your query to allow for restrictions on other custom fields.
args['meta_query'] = array(
array(
'key' => 'Community',
'value' => '$community_choice'
)
)
meaning: i’m giving top priority to “title”. then if not provided, check for “price” finally, if neither are set, the default is title
Related Posts:
- WP_Query – Order results by meta value
- ORDER BY custom field value
- Sort posts by custom field numeric value using dropdown
- Trying to perform complex custom field query with order by set to field value
- Order Posts by Closest Numeric Values
- Is there a way to do multiple ordering on a multiple meta_query?
- Order by custom field date with ASC order
- Order Custom post type loop by custom field (datepicker)
- Sorting within nested queries / multiple meta keys
- Ordering posts by anniversary using only day and month
- Order by Custom Field date not recognized
- Comments form custom fields order
- If value present, order posts by two consecutive custom fields
- Sorting posts by multiple values, combined
- Sorting posts by custom fields in meta_query
- Order RSS content by an advanced custom field value
- Alter main archive, to show posts with meta as last
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Change order of posts
- Meta query with multiple custom fields for archives page ordering problem
- Ordering posts by custom field named “date” in backend
- query posts custom field calculation value
- WP Query – Is this correct?
- Using abs() with custom field in orderby statement
- ORDER BY custom field value out of where clause
- Sortable Custom Columns not sorting correct
- Order custom fields alphabetically
- Problem with writting correctly a query posts args in WordPress
- How to query posts by month based on date custom field?
- Ordering by ACF custom field vaule
- Sort by an ACF field in a tax_query
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
- How to properly get popular Posts by multiple Values
- Order a query by meta_value and then by post_date
- Order by custom field in query multiple
- Can’t sort custom column on user.php by number / meta_value_num?
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Using meta query (‘meta_query’) with a search query (‘s’)
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Show Custom Fields in Quick Edit
- Where are custom field values stored in the database
- Validating Custom Meta Box Values & Required Fields
- Max length of meta_value
- Add custom fields to wp native gallery settings
- How to fix missing custom fields after upgrading to WordPress 4.8.1?
- How to enable custom fields for pages (if not a bad practice)?
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Custom field/meta populated by dropdown of existing posts?
- Difference between meta keys with _ and without _ [duplicate]
- Is there any action filter/hook for validating a custom field before publishing the post?
- Remove Dimension from wp_get_attachment_image
- Orderby meta_value only returns posts that have existing meta_key
- Underscores in custom fields
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- Query Posts or Get Posts by custom fields, possible?
- How to enable revisions for post meta data?
- Sortable Custom Columns in User Panel (users.php)?
- Any way to add custom options to Gallery Settings?
- The “_encloseme” Meta-Key Conundrum
- Individual Widgets per Page
- Add subtitle to Woocommerce product title
- Best way to programmatically remove a category/term from a post
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- SQL Query to copy value of a meta_key into another meta_key
- ‘Preview Changes’ for custom meta boxes?
- Adding a custom field to the site identity menu
- Using TinyMce with textareas in meta boxes on custom post types
- Filter WP_Query for posts having a certain meta-value
- How to correctly call custom field dates into a posts_where filter using SQL statements
- Using get_post_meta with new_to_publish
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- Add a Jquery Datepicker to custom field in post edit
- add meta box – custom field : which to choose?
- Preserving line breaks when saving and displaying custom fields data
- How to return Meta data from the REST API?
- Advanced Custom Fields – Get custom fields from parent page
- Can I query custom meta data through WP_Query
- Add custom field to the archive page?
- Order get_terms() By Custom Field
- Saving custom data for each user
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- Tabindex on text input immediately after WordPress title input
- Including custom fields in search?
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Attaching Metadata to a Taxonomy Item
- Add metabox to document tab in gutenberg