最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post meta - Unset field from an array not working as expected

programmeradmin1浏览0评论

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]);
        }
    }                   
}
发布评论

评论列表(0)

  1. 暂无评论