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
- Sort posts by category name and title
- Query posts from current year
- Why does get_the_time(‘F j’) return November 30 for all posts?
- is_archive() doesn’t work on public query var archive pages?
- Order post by year DESC and month ASC
- Possible to get posts from multiple meta keys/values in a single query?
- Difference between fragment caching and wp_cache
- Meta query with order by another custom field
- How to display all posts with today’s same month and day only?
- How do I search inside specific taxonomies in WordPress
- Show featured image as background image from postQuery
- Using $wpdb->update but confused on the WHERE in and SET
- Make one query for adding entries to database
- add_query_arg() and empty variables inside
- Query Strings and Woocommerce
- Style Post Differently In Query
- WordPress post type “event” query string fix?
- How to orderby multiple meta fields if some fields are empty
- How to redefine the sorting of product categories by menu_order?
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Function to delete a post, it’s children and it’s grand children (half way there already)
- How to sort posts inside categories
- Dynamically adjust single-posttype.php query, based on current taxonomies
- Change the destination of the URLs in post.php
- get_users with array as meta_value
- exclude pingbacks from wordpress SQL query
- Query to view scheduled or draft post
- ASC and DESC separately from orderby
- Sort a list of a CPT ( job) if a meta is empty
- Trying to get all links in my posts
- Restore WordPress Backup Locally?
- Query String for the WP_QUERY parameters
- Sorting of coupons in the right way
- excludeCat function reverses order of blog posts
- Form Data Causes “Page Not Found”
- How to search for articles containing two words?
- Where can I find the SQL to get the most used information by wordpress database?