When I have complex querie to do,
I often use a prequery to get the good post_ids.
Then I pass this list of post_ids to my main query via the post__in
parameter of WP_Query.
$meta_key = 'RepeaterName_%_FieldName';
$meta_value="MyCustomValue";
global $wpdb;
$post_ids = $wpdb->get_col( $wpdb->prepare(
"
SELECT pm.post_id
FROM $wpdb->postmeta pm
WHERE pm.meta_key LIKE %s
AND pm.meta_value = %s
",
$meta_key,
$meta_value,
) );
// Or with another custom $wpdb request
// https://developer.wordpress.org/reference/classes/wpdb/
Then we add $post_ids
to main query
if ( !empty( $post_ids ) ) {
$post__in = $query->get('post__in');
if ( empty( $post_in ) ) {
$query->set( 'post__in', $post_ids );
} else {
$query->set( 'post__in', array_intersect( $post_ids, $post__in ) )
}
}
All this code must be placed in the pre_get_posts
filter.
I hope that the response is up to your expectations.
Related Posts:
- Separeting product from post in search result
- wc_get_template_part( ‘content’, ‘product’ ) | Where is this file located?
- Show only geolocated user country into Woocommerce checkout country fields
- pre_get_posts with WooCommerce Shortcode Query
- Reverse engineering of WooCommerce Storefront filters
- How to modify “[Product] has been added to your cart” in WooCommerce?
- WordPress codex: apply_filters – clarification on creating a new hook on the fly. How do we use it?
- Is there a Woocommerce hook that fires when applying a coupon but before checking if it’s valid?
- Filter on a custom product attribute in WooCommerce using meta_query or tax_query [closed]
- Rewriting Woocommerce Product Filters To URL Segments
- What is the action hook for an order that fails on frontend checkout in WooCommerce?
- woocommerce_get_price filter hook not working for product variation price
- Accessing parameters when adding filter
- Using a filter with multiple parameters and $this
- Remove add to cart icon/view product button woocommerce
- Woocommerce get billing state manually
- Redirect customer to login page (with other signup plugin) if user not logged in when proceeding to checkout
- Using a filter to change a path
- Pre filter woocommerce products to remove a certain category of products
- Can’t filter out variable products in sale from wp_get_products loop (or shortcode) [closed]
- How to apply these filters
- Why does my loop breaks the css below?
- How to add order status class to the body tag?
- Redirect no product url’s to static url
- What Hook/Action is performed when a field in checkout form is changed in WooCommerce
- How can I remove a WooCommerce Product Tab’s sub section in wp-admin?
- Filter WooCommerce archive pages by an additional category
- Custom tax_query filter not working for Woocommerce product categories
- How do I create a filter to hide the One Click Accessibility plugin button in WordPress?
- manage_shop_order_posts_custom_column() hook is Not working In Functions.php file in my WordPress active theme
- Display custom product option in admin order details
- Woocommerce pre_get_posts query variation meta data not working
- How to create a WooCommerce Product filter based on PHP foreach
- unable to customize query to get filtered products by meta_key
- How to add custom checkboxes from loop to WooCommerce product variation options?
- Woocommerce : Add name filed of checkout page to buyers wordpress display name
- Two Filter Issue [closed]
- apply_filter and add_filter conflict
- Woocommerce / Product Columns on Shop Loop / Responsive
- Woocommerce – Hide shipping at all, if only certain product or products with certain shipping class is in the cart
- Running JavaScript after using WooCommerce Filter Plugin
- Redirecting orders by company field
- Combine one action and one filter
- I’m getting error Ultimate WooCommerce Filters
- How to add woocommerce product price filter widget to other page
- How can i add product Accessories from front-end using custom php form?
- How to change lost password email text using custom plugin wordpress?
- Overriding Plugin function in your child theme
- Update / refresh mini cart, after custom AJAX add_to_cart event
- Filter orders in Admin area based on logged in user
- WooCommerce Tax Filter Not Working
- Add suffix to price html does not work
- woocommerce price filter not working when change currency
- With what hook do I remove WooCommerce existing Product Data Tab form fields?
- Custom product loop avoiding duplicates
- AffiliateWP not calculating multiple quantities when using affwp_calc_referral_amount filter
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Add second price option based on payment method at cart item price
- How to get the attributes based on dependency in woocommerce?
- Reposition variation stock message
- Add custom ID to WooCommerce product tab
- Remove “Choose An Option” on Product Variation & Auto Select Instead
- check if current url/page equals checkout page [closed]
- How to Order by random on a SQL query
- Move add to cart in Woocommerce
- Remove Order List Row Link in WooCommerce Admin?
- How do I hide out of stock products from homepage but not from catalog?
- Woocommerce Porto Theme Hide Selected Categroy for Breadcrumbs
- Woocommerce custom search
- Make a Read More toggle in the_content on single-product in Woocoomerce
- WooCommerce Base Page Featured Image Custom Theme
- How to search variable product by its variation id in woocommerce admin product search box?
- Hide inventory message on product page based on available stock quantity
- Remove sale signs from site in branded? [closed]
- Create a regular post for every WooCommerce order
- relation OR instead of AND – Filtered term ID’s in loop
- Hooks For Design variation in woo commerce single product page
- Dokan stock management
- Access custom meta_data in processing order email
- Woocommerce – how to round up all prices to end in .99
- Woocommerce cart table too wide [closed]
- Display product attributes for current product
- Woocommerce Add to Cart function
- How to show woocommerce login / registration form in modal
- Woocommerce – display all sold out products
- Woocommerce how to show most selling products by category
- Hide a shipping method if cart total is higher than an amount
- error 500 in Back Office when using a woocommerce function in functions.php
- Send data to external websites when there is an update or create a post
- WordPress pointing animated GIF images with wrong file name upon upload (GIFs animation not working)
- How to update all products with same SKU prefixes when updating stock with CSV?
- What is the best and cheapest way to generate dashboards about conversions data and store users? [closed]
- Sort by price when price is set in multiple keys
- Add a custom code with custom link after add to cart for every product
- WooCommerce product permalink based on product’s current category
- Disable duplicate WC product category URLs
- how should i get products based on tags in woocommerce
- Hide empty categories on widget
- Add custom text to product category page
- Woocommerce permalink URL change in DB