If you only need to use URL query parameters, you should use simple links instead of form.
If you want to use form, but still want to use URL query parameters, you should definitely go with javascript.
But, if you really want to use form and $_POST data, you can use this:
$orderby = isset($_POST['orderby']) ? $_POST['orderby'] : null;
switch ($orderby) {
case 'a_to_z':
$field = 'post_title';
$sort="ASC";
break;
case 'z_to_a':
$field = 'post_title';
$sort="ASC";
break;
case 'date_oldest':
$field = 'post_date';
$sort="ASC";
break;
default:
$field = 'post_date';
$sort="DESC";
break;
}
Related Posts:
- Notice thrown when creating numeric pagination on custom query
- and tag not working
- wordpress udpate query not equal to
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Write WP Query that selects posts that are part of the same two categories
- WP_User_Query orderby meta_val_num
- WP_Query custom order and pagination
- How to SQL query posts IDs by categories AND authors?
- Unable to paginate a custom page query
- Include one page/post into query which is already returning posts
- I am officially missing something about transient posts
- Insert images into wordpress post with a query
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- Start Query from 2nd Post without offset
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- meta_query where the meta value is not the post title
- Post incorrectly excluded when using “category__in”?
- Query multiple post types, but different order for each
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Filter products on category AND tag
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Pagination of custom page with custom fields query
- Query pages created by deleted users
- setting offset to category number in archive page
- Woocommerce Get Orders By Meta Value
- Any way to use FETCH_KEY_PAIR with $wpdb?
- pre_user_query vs pre_get_posts
- Exclude post from wp_query based on custom field boolean
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Get posts that match defined arrays of tags
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query
- Meta query orderby meta_value_num sorting by role first
- How to get meta key list efficiently?
- Order posts by tags count?
- Query against multiple locations within single custom post type post
- Why pagination is not working with tax_query param?
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- Strange results from WP_Query
- Display posts side by side with custom query
- How to get_comments() ordered by date and parent?
- I need query_posts() to order results first by a meta value and then by post ID
- WP_Query & Duplicate entries
- How to query 5 users in random who have published more than 10 posts
- How to query users by post count no less than 10
- WP Query. Ordering posts by another post types meta
- Add to search posts query array with post IDS which will appear first
- return child post if available otherwise parent post
- Search has query that will return no results
- Is my code correct?
- How to make a search query if not found in post table then search in postmeta table?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- WP Query – Search in title or author_name
- URL to Post Archive of Custom Query
- Query by meta value (add a dropdown of all values)
- Meta query doesn’t remove placeholder escape before query
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- How to show post title in content editor in backend?
- How to show terms from another taxonomy
- Adding Category in WP_Query Not Working
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- What is the best way to reset a search on a meta_key / meta_value?
- Ignoring ‘a’ when sorting posts
- how to show more than 1 post into three columns query
- How can I modify standard search query to include also ACF custom fields values?
- Using the same WP_Query for shop and widgets in WooCommerce shop
- How can I get all the posts that are related with a specific taxonomy term?
- Fetch only categorized posts
- Bring a post to the top of the query if it’s in a certain category?
- orderby in WP_QUERY – Use the order from the Dashboard
- Random posts in WP_Query when searching by tag
- WP_Query with child element
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- Custom pagination (Title, date and teaser)
- Using URL variables on a custom WP_Query
- Ordering Posts by parent category, name ascending
- Query posts in current category but not attachment format
- Filter posts/pages by user_role array
- WP_Query always returning the last custom post
- WP_Query secondary query failing
- How to get query results for the next page
- Search Functionality broken by the wp 4.2 update
- Issue attempting a wp_query_posts with tags
- How to query post into a complex slider
- wp_query – Modify $query to include duplicate content
- Using WP_Query to re-query and sort results using a date?
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- Pagination is not working on custom query inside a custom home page template
- Loop through multiple custom fields with increasing number
- Combine privileged users array with my current query
- Pagination in custom query in a category page