You can use the parse_query action hook, and set the orderby and order paramenters.
function my_mod_search($query) {
if ($query->is_search()) {
$query->query_vars['order'] = 'ASC';
$query->query_vars['orderby'] = 'post_date';
}
}
add_action('parse_query', 'my_mod_search');
Related Posts:
- Order posts ascending from posts in array
- Ascending & descending posts on same page with IF statement
- what are the numbers between curly brackets in search query
- wordpress query – orderby child post date
- Search custom post type by meta data
- Query by one meta_key and sort by another (possibly NULL value)
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Fulltext search in posts sorted by relevancy
- Filter query posts by the count of metas for a meta key
- search through post-type attachments titles
- can’t get query to order posts by acf datepicker
- Sorting Grids with Essential Grid and Events Manger
- mySQL query. ORDER BY meta_key
- Change searched term
- sort search results by custom fields using dropdown
- Order query by post meta value
- Search query -> Show all pages except certain template
- Temporarily storing main search result
- Order posts by custom field DATE value
- Ordering by a metadata subfield in WordPress?
- Query based on title, with ‘compare’ => ‘IN’
- is_search called incorreclty
- Attempt to improve WP search, can someone check my SQL query?
- Searching With Apostrophe
- Can’t seem to do combined query AND sort?
- sort query results by newest
- How to reset usual $query on search page to push custom $wpdb query there?
- Order by title – but now built in wordpress func, sort the_title
- Ideas how to search & replace post_content when string contains a newline?
- How to insert Collate into WordPress search query?
- Slow Search Queries – How to exclude pages, media, excerpt, authors, private posts?
- How to interfere to default search to make it search in custom fields?
- Querying with WP query using meta key price
- Re-sort get_posts query results
- Order terms by count – missing terms
- How to rearrange a pool of posts joined using two queries?
- How to “orderby” the first array in a meta_query that uses multiply keys?
- Sort query_terms_list for post_tags alphabetically
- JetEngine Query Builder – order by value from repeater
- WordPress search in modified post title
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- Add rewrite rule for archive search
- Custom post type order by post_title
- Orderby event date (if it exists) or post date (if it doesn’t) – how to reorder posts based on meta value OR date
- Restrict WordPress search to a single ACF field
- wp query multiple values > display a specific value first
- Modify behaviour of “s” parameter in wp_query
- Sort by postmeta on when searching
- Pagination adds search query (again)
- Order WordPress Query by Custom Field While Still Using Tax_query Argument
- Speed up search query that searches in post meta?
- “order” does not affect order of custom query
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- How to make MySQL search queries with quotes
- Query Posts that have or don’t have a meta_value and order by the same ASC
- $query->set( ‘post_type’, ‘post’ ); not working
- Apply ordering args to newly merged queried
- search.php is not generating the right results
- Sort loop with query in the link
- Run search query again without pagination gives no results?
- WP_Query orderby meta key/value suddely stopped working
- Query posts alphabetically within this function
- Elementor – Sort by name
- is_search called incorrectly
- How to display SQL query that ran in query?
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to Optimize WP site for millions of posts
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to Change Order of Posts in Admin?
- How to get comments by post ID?
- ORDER BY custom field value
- Differences between wpdb->get_results() and wpdb->query()
- Sorting: custom query with orderby meta_value_num THEN by title
- group search results by post type?
- Is there a way of increasing the speed of this query?
- Random sort within an already sorted query
- Get all image from single page using this query
- Different post sort order within different categories
- How can I query all users who registered today?
- Get Terms by IDs with IDs order
- Sort posts by Date (DESC) and by Title (ASC)
- Reversing the order of posts AFTER the query is performed
- Sort custom post type list table by display name of a user id stored as post meta value
- simple sql query on wp_postmeta very slow
- Using WordPress public query variables
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Sort posts by category name and title
- Create pagination and order according to alphabet
- wpdb get posts by taxonomy SQL
- How to get order of posts?
- How to List Events by Year and Month Using Advanced Custom Fields?
- WordPress post sorting with AJAX
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- Custom WP_Query order by post_meta and (author) user_meta
- How do I search events between two set dates inside WP?
- How many WordPress SQL Queries per page?