Hi,
I need to query post ‘maintenance’ and exclude post with specific values ACF taxo ‘reparation_satut’==561
I read i have to use pre_get_post but as my query is in another function, i don’t understand where and when pre_get_post will be applied.
I would like to apply this filter only on my query not eveywhere on the site.
thanks
function exclude_repaired( $query ) {
$custom_meta = array(
‘key’ => ‘reparation_statut’,
‘value’ => ‘561’,
‘compare’ => ‘!=’
);
}
add_action( ‘pre_get_posts’, ‘exclude_repaired’ );
function display_form_maintenance(){
$args = array( /// here i don’t want posts with reparation_statut ID ==561
‘post_type’=> ‘maintenance’,
‘posts_per_page’ => -1,
);
echo ‘<select>’;
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo ‘<option value=”‘.get_the_ID().'”>’.get_the_title().'</option>’;
$post_id = get_the_ID();
}
}
echo ‘</select>’;
wp_reset_postdata();
}