In one of my template files, I am running the standard WP_Query and loop etc. This is not within the product archive etc, just a regular custom template.
<?php $args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => $meta_query
); ?>
<?php $post_query = new WP_Query( $args ); ?>
<?php if ( $post_query->have_posts() ) : ?>
etc....
From my filters.php file, I want to hook into that WP_Query and grab the IDs returned. I suspect it's a pre_get_posts approach but I need it to be focusing on the WP_Query which I am running to get products. Elsewhere on the site are other WP_Query's being ran.
How can I hook into the currently running WP_Query for product post type and grab the IDs. I don't want to do this within the loop in the template file.
source https://stackoverflow.com/questions/76695420/grab-ids-of-products-from-wp-query-via-a-filter-whilst-its-running-on-a-templat
No comments:
Post a Comment