1

I'm trying to filter a custom options page from acf that is used to create menus based on items that are added on the backoffice, but I'm not being able to unset the fields when they aren't supposed to be shown in the frontend for non logged users.

I've setted the post filtering in the backoffice correctly, as it is working to filter content on the main menu and also when someone tries to access directly the post.

An example of what is in the post_meta field filtering_profile field is uk_user. For each post it can have multiple pairs of country_profile.

You can see the code below, I'm probably doing some basic mistake but I can't see to figure out where I'm doing it.

foreach ($footer_menu as $k => $column) {
    if ($column['mode'] !== 'menu') {
        continue;
    }
    
    foreach ($column['page_link'] as $key => $link) {
        if (is_array($link['item']) === false) {
            continue;
        }

        $post_id = url_to_postid($link['item']['url']);
        $post_type = get_post_type($post_id);
        
        if ($post_type !== 'post_typeA' && $post_type !== 'post_typeB') {
            continue;
        }
        $post_meta = get_post_meta($post_id, 'filtering_profile');
        if (!isset($post_meta[0]) || get_post_status($post_id) !== 'publish') {
            $link[$key] = false;
        } else if (!in_array($country . "_" . $type, $post_meta[0])) {
            unset($footer_menu[$k]['page_link'][$key]);
        }
    }                   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.