• Resolved awfief

    (@awfief)


    Hi all,

    This is a question AND answer. After not finding the answer on the board, I modified code myself before asking. Not too hard.

    Basically my question was, “how can I get the montharchives plugin and the viewlevel plugin to play nicely?” I searched and didn’t find the answer — there is probably one out there, but I couldn’t find it. So to get the montharchives plugin to respect the viewlevel, so that the titles of articles that shouldn’t be seen by a user didn’t show up, I did the following

    (all in montharchives.php in the plugins folder)
    Just after the line that reads

    global $_GET, $tableposts;
    add
    global $_GET, $tablepostmeta;
    get_currentuserinfo();
    global $user_level;
    $viewlevel=$user_level+0;

    (the +0 is important, otherwise a user_level of 0 shows up as ” when we’re comparing in the query later. I don’t know why, but there ya go.)

    around line 35, there’s a while loop that starts:
    while($date = mysql_fetch_array($querymonth)){

    change the queryline after that to read:

    $query = mysql_query("SELECT *, year(post_date) as year, month(post_date) as month FROM $tableposts LEFT JOIN $tablepostmeta on $tableposts.ID=$tablepostmeta.post_id WHERE year(post_date)='$year' AND month(post_date)='$date[month]' and ($tablepostmeta.meta_key is NULL or $tablepostmeta.meta_key!='viewlevel' or ($tablepostmeta.meta_key='viewlevel' and ($tablepostmeta.meta_value IS NULL or $tablepostmeta.meta_value<=$viewlevel))) ORDER BY id desc") or die(mysql_error());

    This will work even if you disable the viewlevel plugin later on. If montharchives is still being developed, this would be great to put in, or at least in the instructions for viewlevel, if that’s still being developed.

    Hope this helps people. I’m also open to people writing back and saying how I *should* have done this, as I feel there’s probably a solution that was in the docs or that someone else solved. . .I looked and couldn’t find it, but maybe I’m blind.

    -Sheeri

  • The topic ‘montharchives and viewlevel’ is closed to new replies.