<?php
function exclude_protected_memberpress_posts( $query ) {
// Ensure we are not in the admin area and it's the main query
if ( ! is_admin() && $query->is_main_query() ) {
// Check if we are on the repeater field context
if ( function_exists( 'get_field' ) && get_field( 'your_repeater_field_name' ) ) {
$posts_to_exclude = array();
// Get all posts
$posts = get_posts( array(
'post_type' => get_post_types(),
'post_status' => 'publish',
'numberposts' => -1
) );
// Loop through each post and check if it's protected
foreach ( $posts as $post ) {
if ( MeprRule::is_locked( $post ) ) {
$posts_to_exclude[] = $post->ID;
}
// Exclude protected posts from the query
if ( ! empty( $posts_to_exclude ) ) {
$query->set( 'post__not_in', $posts_to_exclude );
// Attach the 'exclude_protected_memberpress_posts' function to the 'pre_get_posts' action.
add_action( 'pre_get_posts', 'exclude_protected_memberpress_posts' );