Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Restrict Results Based on Paid Memberships Pro Level › Reply To: Restrict Results Based on Paid Memberships Pro Level
June 25, 2024 at 9:58 am
#48560
Keymaster
Perfect!
Okay, so based on all the information I got this:
add_filter(
'asp_query_args',
function ( $args ) {
$level_tag_map = array(
2 => array( 33 ),
3 => array( 34 ),
);
$user_level = pmpro_getMembershipLevelForUser();
if ( $user_level === false ) {
return $args;
}
if ( isset($level_tag_map[ $user_level->ID ]) ) {
$args['post_tax_filter'][] = array(
'taxonomy' => 'post_tag',
'include' => $level_tag_map[ $user_level->ID ],
'allow_empty' => false,
);
}
return $args;
},
10,
1
);
I couldn’t test it obviously, so please be careful.
Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.