Forums

RESTRICT CATEGORIES (1 post)

  1. tudorelg
    Member
    Posted 2 years ago #

    Hi all,
    I am using "restrict categories" Author: Matthew Muro
    Version: 1.6.1 and I'm having a little problem.
    I have 30 categories displayed as pages, the theme I use allows me to insert at the top of the categories a link to the post-new.php. The plugin hides categories that I don't want users to use.
    I also have a session variable that is stored every time the user visits a page that is displayed as category.
    Basically, what I need is when the user starts a new post launched from the category "english" he only needs to choose the category "english" and the others to be hidden before publishing the post (having all 30 categories listed is not good because the user will probably use 5 or more categories and his post will appear in 5 category-pages, and that will create confusion, or maybe will post in the wrong category).
    What I managed to do is this:

    function RestrictCats_cat_filters( $cat_list ){
    global $cat_list;
    session_start();
    $my_last_category= $_SESSION['my_last_category'];

    if ($my_last_category=="English")
    $cat_list = rtrim( $cat_list[0], ' ,');
    elseif ($my_last_category=="Romanian")
    $cat_list = rtrim( $cat_list[2], ' ,');
    elseif ($my_last_category=="Italian")
    $cat_list = rtrim( $cat_list[4], ' ,');
    elseif ($my_last_category=="French")
    $cat_list = rtrim( $cat_list[6], ' ,');
    else
    $cat_list = rtrim( $cat_list[8], ' ,');
    /* Clean up the category list */

    /* If there are no categories, don't do anything */
    if ( $cat_list !== '' ) {
    add_filter( 'pre_get_posts','RestrictCats_posts_query' );
    add_filter( 'list_terms_exclusions', 'RestrictCats_exclusions' );
    }
    }

    and it worked with 3 categories but with more it won't work.
    Any help will be much appreciated,
    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic