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
- Show Featured products with custom taxonomy template
- How to list some posts first in the loop based on post id
- Insert variations via woocommerce api [closed]
- Display order items names in WooCommerce admin orders list [closed]
- How to order posts tag by tag?
- Remember page before login page, redirect to that page after login
- Hook and send Woocommerce data after click Place Order button
- WooCommerce lost password reset flow not working with SendGrid (redirect loop)
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Change add to cart text if a product is in cart on WooCommerce
- Woocommerce – Hide a Column in Cart Table
- Get user payment details when payment successfully done in woocommerce [closed]
- How to assign specific attribute to variation for woocommerce product?
- How to change page via login as user and admin
- How to remove the sub-category from Woocommerce product URL
- Find woocommerce product ID by custom field value?
- how to use different page design for different category
- Getting WordPress database error Deadlock
- How to get_template_part using AJAX?
- How to track post number on the_loop
- WooCommerce WebHook Retry
- Place Order button in Checkout
- Can I set my WP_Query to be a Main Query?
- woocommerce – How Can I add author metadata for a product? [closed]
- Show scheduled posts in main loop but not in WP_Query?
- shortcode to display woocommerce cart total
- Woocommerce – Want to move the product tabs below short description
- Where is the CSS class ui-sortable-handle for WC_Admin_Taxonomies added?
- WooCommerce: “account is already registered with your email address”
- Enter name and email on the Product page and keep the input data on the Checkout page
- Woocommerce: Same gross price for different tax rates [closed]
- add shoppy.gg to woocommerce instead of add to card [closed]
- List of shipping on product page [closed]
- Woo commerce using add_fee to add discount to cart not saving discount amount the admin backend when guest user is shopping
- How to change Attribute Type
- WooCommerce plugin won’t let me access settings
- How to edit T&C checker text in Woocommerce checkout page? gettext?
- What is the reason for two classes storefront_woocommerce and storefront
- Get email type inside email template – order emails