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
- Filtering by Hard-coded WooCommerce Product Attributes
- get available brand attribute in woo commerce shop page, category page
- How to add field new in account bacs in woocommerce?
- Woocommerce: hide “Price display suffix” when the VAT is zero
- Filter orders list by shipping method for each user in WooCommerce
- PHPWord and DOMPDF: PHP Fatal error: Uncaught Error: Class “Dompdf\Dompdf” not found
- How to Add an option to display dimensions in both cm and inch in the Additional information tab in woocommerce?
- Possible to overwrite load_template function in plugin using functions.php
- How to prevent woocommerce product tag field from update?
- Adding a div wrapper for postcode and city fields on checkout page
- wordpress woocommerce templates did not update?
- How to Filter the Custom term loop based on dropdown
- Problem with “is_user_logged_in()” and woocommerce (Code for custom media upload for each author.)
- Custom Auction Product Attribute Section [Dokan & Woocommerce]
- New multisite Server Not Found
- Searching in categories AND custom fields
- Getting Uncaught SyntaxError: Unexpected token ‘
- How to detect changes in WooCommerce store (react)?
- WooCommerce custom SVG coloring tool [closed]
- Woocomerce erro shipping [closed]
- WooCommerce admin>edit-comments show none [closed]
- How do I prevent double the amount of stock being reduced with this Split Order Woocommerce Code? [closed]
- woocommerce pagination. not working when sorting used
- WP sites/Woocommerce stores in multiple subfolders broken after migration
- Woocommerce Gallery Image Caption: Use “caption” — not “alt tag”. Keep alt tag as is
- Getting Uncaught SyntaxError: Unexpected token ‘
- Woocommerce deleted and replaced my WordPress front/page. How do I restore my original page?
- How to block checkout process when session origin is unknown?
- Woocommerce: “Edit Page” changes not displayed on Shop page [closed]
- Check If Woocommerce Tax Name Exits On Checkout Page [closed]
- Link post thumbnail image when automatically creating Woocommerce product from a WordPress post
- Taxclass based on certain conditions: location+userrole
- Using WordPress single product page hangs on loading images not already cached
- Automatically Append Country Code to Phone Number in WooCommerce Manual Orders (Admin Dashboard)
- WooCommerce uninstalled but ‘My Account’ prefix still showing on an existing page
- Additional Images in Media Folder after importing products from CSV to WooCommerce
- Removing unwanted role after purchase
- How to Filter Products Based on Categories on the Cart Page?