Yes,
You can call action “pre_get_posts”.
add_action('pre_get_posts','search_filter');
You can add parameter :
$args = array(
'post_status' => 'publish',
'posts_per_page' => 6,
'paged' => $paged,
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
You can use above parameter e.g. :
function search_filter($query){
if ( !is_admin() && $query->is_main_query() ) {
$query->set('post_status', 'publish');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
}
}
Related Posts:
- Is it possible to sort the post based on a custom field?
- How to separate posts in loop?
- Loop through custom taxanomy in post and display custom fields from posts
- Convert post meta to custom taxonomy?
- Count tags for current post and save into custom meta field (and update it on post edit)
- ACF – Get unique values of array
- Remove Custom metabox from particular page template is used
- sort Posts by custom user filed
- How can I show custom field according to taxonomy?
- How do I create a term for every value of a post meta?
- Can I access a post meta field before the loop?
- how to store values in database at hierarchical view
- Best structure for entering recipes in a WordPress theme?
- If Custom Taxonomy
- WP REST API – get custom taxonomies based on terms & filter
- How can I reduce amount of ifs and else ifs in this specific block of code?
- Returning One custom taxonomy term name
- Exclude taxonomy term from all loops, but having it on widget
- wp_query not resetting, last post hanging
- Using WP_Query and Query_post for the loop?
- Copy/clone/associate Custom field to Custom Taxonomy
- saving meta/custom field to tag
- How to support fifteen thousand terms in WordPress?
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Different Taxonomy Values for Each Post
- Loop to display ONLY custom taxonomy parent information [closed]
- Filter through custom taxonomy with an array of taxonomy IDs
- What’s the best way to add taxonomy’s image in 2017?
- Count of posts by different parameters?
- Why can’t I access Custom Taxonomy metadata?
- WooCommerce custom taxonomy as meta?
- List terms of custom taxonomy if matches other taxonomy
- SQL / wp_update_post: change post custom field to CPT post taxonomy
- Only display latest custom taxonomy post
- Filter by Custom Taxonomy AND Custom Field
- Can You Build Page Templates Without Extra Files
- how to get the post id in the option tag
- How to get the term description in a taxonomy term archive query?
- Chaining Taxonomy Queries
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- Extra Meta Data for WordPress Multisite Taxonomy
- Taxonomy or Custom Field
- Sort taxonomy page alphabetically by meta rather than default post date
- Problem with sorting in custom child taxonomy archive page
- Is there a way to nest taxonomies or custom fields deeper than one level below the post type?
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- How to use custom slug and custom templates for custom taxonomy?
- How to add custom checkboxes from loop to WooCommerce product variation options?
- Create multiple taxonomies with custom fields values on the fly when creating new posts
- display ACF repater field in archive page
- How to add a shortcode function that returns the taxonomy slug of the actual post within the loop
- Custom field with terms from another taxonomy programmatically
- Group posts in a category based on tags in custom taxonomy
- How to loop custom posts that have an exact match in taxonomy terms?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Create new Taxonomy, add extra fields, register terms AND extra fields values?
- Get post meta value outside of the loop
- Adding a Section for Visitors
- Dropdown (with onChange) with custom taxonomies
- Custom taxonomy template for custom fields loop [closed]
- ACF Custom field not showing in Timber Taxonomy page
- Pre_get_post custom taxonomy combined with custom fields?
- Adding a checkbox field to a (custom) taxonomy
- Custom taxonomy shows full articles
- Add and Custom category for posts “PAGE”
- Output slugs to use as class names for every taxonomy a post is attached to
- Reset custom taxonomy meta data after saving
- Multi level archive
- how to filter the data’s comparison operators (>= &
- List active taxonomy terms
- Register custom taxonomy from a Advenced custom field option page
- Avoiding stripping of HTML in Custom Taxonomy Meta Field
- Order by custom field attribute
- Trying to achieve row posts below category with multiple loops in custom tax
- add custom fields in custom taxonomy meta box in wordpress-3.5.2
- Update fields with post object and custom tax with wp_insert_post
- Use custom field as tag slug
- Custom Taxonomy + JQuery Tabs
- WordPress show posts from children terms of a taxonomy term
- Advanced search form with filters for custom taxonomies and custom fields
- Transfer taxonomy to custom field
- Custom Fields link to other pages, not search
- Taxonomy Extra Meta [duplicate]
- Loop custom post type by taxonomy (Category)
- Any way to make custom taxonomy field searchable?
- Advanced WordPress search form based on custom taxonomy and custom meta value
- Get custom taxonomy value of post and output posts in same taxonomy
- More than one Hierarchical Taxonomy and SEO
- Order by a meta field in query loop
- How much worse is querying custom fields compared to custom taxonomies, quantitatively
- How home my code doesn’t display any feature image? Looping through post from a taxonomy and not getting feature images back
- Loop posts without any taxonomy
- How to looping taxonomy terms?
- How to show to show post list under the specific category name using jetengine query?
- I want to show image from custom field image on my custom page template
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
- How to handle custom taxonomy archive when no posts will have that taxonomy
- How can I list all the meta in a custom taxonomy?
- ACF – How to get custom taxonomy term image field
- Grouping posts by 2 different taxonomies