for a simple meta query you can do this:
function wpa_47150( &$query ) {
if(!is_admin()){
set_query_var('meta_key', 'test_field');
set_query_var('meta_value','bacon');
}
}
add_action('pre_get_posts','wpa_47150');
i wasn’t sure it was going to work, but apparently you can set the whole meta_query object this way too
function wpa_47150( &$query ) {
if(!is_admin() && is_post_type_archive( 'test_post_type' )){
$metaq = ( array ( array(
'key' => 'test_field',
'value' => array( 10, 50 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
))
);
set_query_var('meta_query', $metaq );
}
}
add_action('pre_get_posts','wpa_47150');
need to adjust the conditionals to your specific case
Related Posts:
- Ways to have multiple front-page.php templates that can be swapped out?
- Add custom PHP and HTML to the_content()
- Create custom page templates with plugins?
- Manually set global $post vars with an ID, in order to use template tags
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Is it possible to stop selected plugins from loading on certain template pages?
- Output before and after the loop
- Define Function in functions.php or plugin and call in theme loop
- Add Archive Page Template via Plugin
- How can I let users to access plugin functions based on roles?
- Why am I sometimes getting a 404 error when I try to update a page with Elementor?
- Template for custom post type shows all posts instead of just one
- Fastest way to loop through all posts?
- Template plugin for blog posts? [closed]
- How does WordPress ensure plugins run at the same time and how does it solve a plugin’s dependency on another one?
- Is it possible to upload a template file to a directory that can be used by all themes?
- post expire after x days
- Adding a post shortcode to a page template?
- Can’t get custom posts of taxonomy to show
- Is there any way to get all the name or slug of template parts used in a page?
- Calling custom plugin class methods from a template
- Create a custom page template inside my wordpress plugin
- Display content from custom post type if match to main post category
- how do i remove posts from a WP_Query so the pagination is right?
- New to wordpress: would like to have pluggable main page sections [closed]
- Override global query results without hooks
- Register Page Template from Plugin
- Use wordpress functions in another PHP file
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- Plugin-generated pages use Not Found or Pages Archive templates?
- Insert content of a post into another
- Problem with the Loop – want to limit the access to three free articles
- How to use get_template part in the plugin?
- WordPress Plugin manipulate have_posts()
- Show author on every sub-page
- Get User_id outside wordpress,
- Calling the_excerpt from inside a plugin template file
- Recent posts per category loop?
- URLs Added to ACF Repeater Field are not working
- Import Instagram post to WordPress blog post
- Bulk update wordpress posts
- How to get a list of bundled products using wp_query in woocommerce
- Where to find the code used to render a page that has a shortcode and a template defined?
- Create custom template in plugin and display it into post template section?
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- the_content() printing DOCTYPE, and tags in the middle of page
- How do I create a custom permalink structure for a page template
- Trying to add_action in a loop
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Plugin create pages and use templates
- Get post content from outside the loop with plugin shortcode usability
- Custom form not showing in correct place on page
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Ajax Call in page theme not working?
- Remember the Meta Value With Radio Buttons
- How do I show content from a plugin using the template the site is currently working with?
- How can recognize post’s category?
- Output after specific post in the loop
- How to dynamically change spots of text in custom page?
- Plugin is creating posts twice
- Polldaddy doesn’t show up on own theme
- Pull comments from one page/post into another page/post?
- Multiple images per post – Show random image elsewhere
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Give custom page template a custom post ID
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- WordPress Product Detail and catalog
- how do i fixe Page Builder on a custom page?
- Plugin json page
- How to use custom footer template in a site-plugin?
- Passing variable from template file to the plugin file
- How to differently style pages that display posts of different category in WordPress?
- Create post loop that displays pages by cat ID
- Place content inside the Post Loop
- Custom Page Templates for a complex application – code must sit in a plugin and not the Theme
- Cannot reset a loop in a plugin template
- Displaying image from a repeatable group
- Multiselect value in wp_query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- ‘all’ hook and add_action issue (class based plugin)
- Fake Single WordPress Post (Page) Loop
- single.php fires more than once after clicking on any post to view with different post id each time
- How do i use postMash to order posts in a custom loop?
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Getting Post Permalink Outside of Loop Not Working
- Sort Reviews/Ratings by date on Woocommerce
- Trying to display posts but getting the pages as output
- How to create a page template using custom plugin
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Outputting custom field query from a plugin to the website header
- How to display content depending on the Woocommerce Product Category
- Resources for building a custom event page template
- Page with redirect
- FacetWP custom display based on post type [closed]
- How to provide page_template path in custom plugin using WordPress