• Resolved kcomphlint

    (@kcomphlint)


    We have a system with a post type that contains multiple entries. Each entry is unique and has a unique access level. We need to create a list of items on the homepage so that when you are logged in, you see the posts that you are approved to view. Is there a way to do this with the plugin? Almost like using a conditional for access levels

    For instance:

    I am access level alpha, which can view the “alpha” posts. Homepage has a list of links for alpha, beta, delta, etc. When I login, I should only be able to see alpha.

    Was going to use a custom query to just echo a list of links, but I am not sure that will work. Would be a PITA to have to manually add shortcodes around each link, but that may be the only option. Just making sure there aren’t other options I am missing.

Viewing 1 replies (of 1 total)
  • Plugin Author Joachim Jensen

    (@intoxstudio)

    Thank you for reporting this.

    Currently there is no built-in way to automatically show/hide restricted posts/pages from lists, widgets, or custom queries. It is on the roadmap.

    If your levels restrict specific posts/pages, and not e.g. posts in a given category, you could look into this snippet:

    global $wpdb, $post;
    
    //get levels current user doesnt have
    $other_levels = array_diff(
    	array_keys(RUA_App::instance()->get_levels()),
    	rua_get_user_levels()
    );
    
    //get posts/page IDS that current user does not have access to
    $post_ids = array_flip($wpdb->get_col("SELECT m.meta_value FROM $wpdb->postmeta m INNER JOIN $wpdb->posts p ON m.post_id = p.ID WHERE m.meta_key = '_ca_post_type' AND p.post_parent IN ('".implode("','", $other_levels)."')"));
    
    if ( !isset($post_ids[$post->ID])) {
        //display link
    }

    Otherwise shortcodes would be the way to do it for now. I hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Restrict links on homepage’ is closed to new replies.