Gudlyf’s World

March 8, 2005

Filed under: Techie — Gudlyf @ 2:46 pm

I was using an old Wordpress hack called Show Categories to get around the problem of my not wanting all posts of certain categories showing up on the front/main page. It worked…somewhat. But there were things it didn’t work on, such as feeds and sometimes searches and archive links. There are additional hacks I could do to fix that, but I thought instead that perhaps a new plugin was in order.

This plugin, which is very much in beta, only works in WordPress 1.5+. It adds a new menu link under the “Manage” admin menu titled “Category Visibility”. Once you activate the plugin, go to this menu and you’ll see the visibility settings for all categories. So far I’ve listed options for “Front”, “List”, “Search”, “Feed” and “Archives”, defined as:

  • Front: All posts in the category will not show up on the main page
  • List: The category will not show on the list of categories on the home page (i.e., the list in the sidebar here)
  • Search: The category’s posts will not show up in search results
  • Feed: The category’s posts will not show up in the main RSS/Atom feed
  • Archive: The category’s posts will not show up in archive links (i.e., clicking on the calendar links)

I did not get a chance to test with inherited categories, so if that breaks let me know. I may get around to testing that sometime.

You can grab the latest version here (Version: 0.31)

NOTE: If you’re using the default download of Wordpress version 1.5 (i.e., NOT 1.5.1 or above) download the version here. There’s a database change made in the nightlies that made this necessary for now.

IMPORTANT: As of version 0.28, these versions will create a new table and not use your existing one, so write down the current values if you’re using an older version of this plugin before installing and running this version!

To Do:

  • Put this plugin on WP-Plugins.org (in progress)
  • Allow per-post visibility option. Should be as simple as adding a custom field for posts.
  • Fix issue with number of posts on front page when some are marked to not show up (i.e., you specify 10 posts per page, two of those are marked not to show on the front page, so you instead only see eight posts)

172 Comments »

  1. Nice work.

    Comment by ColdForged — March 8, 2005 @ 4:39 pm

  2. Hi, I tried the plugin but with the following error.

    1. when i click on the Category Visibility under Manage, i got the 404 error saying that “mysite/wp-admin/5150″ was not found.

    2. The “WordPress database error: [Table 'mysite_wordpress.cat_visibility' doesn't exist]
    SELECT cat_ID from cat_visibility” shows up in Manage–>Posts

    Do i need to create the table ? Or it should be automatic created that table?

    Comment by Cara — March 8, 2005 @ 10:32 pm

  3. Hi,
    I get this error message:

    404 Not Found
    The requested URL /blog/wp-admin/5150 does not exist.

    /blog/ is the directory containing my Wordpress 1.5 install

    Comment by charlie — March 9, 2005 @ 5:10 am

  4. Try the new version I must put up (version 0.10).

    Comment by Gudlyf — March 9, 2005 @ 10:18 am

  5. maybe some possible future features would be checking for user lvl? b4 deciding whether to show the post in the category??

    nice plugin though. really useful

    Comment by TedFox — March 9, 2005 @ 11:19 am

  6. Still no go:

    404 Not Found
    The requested URL /wp-admin/plugins/category_visibility.php does not exist.

    The plugin is in /wp_content/plugins

    Comment by charlie — March 9, 2005 @ 12:22 pm

  7. Yes, i got the same error as Charlie.

    And the database problem still remain:-
    WordPress database error: [Table 'mysite_wordpress.cat_visibility' doesn't exist]
    SELECT cat_ID from cat_visibility

    Hope you could figure it out when you are free.

    Comment by Cara — March 9, 2005 @ 1:52 pm

  8. Are you using Wordpress 1.5? Maybe it’s because I’m using 1.5.1-alpha, but I don’t think that’s it…

    Comment by Gudlyf — March 9, 2005 @ 10:58 pm

  9. Another to report the same problems as 6 and 7. Using Wp1.5. I haven’t tried it on my nightly build yet.

    Comment by Ian — March 10, 2005 @ 4:46 am

  10. Ian — Can you try on your nightly please? I’m following what I’ve seen in other plugins, so it’s not clear what’s wrong. The database problem should go away once we get the page to load up ok.

    Comment by Gudlyf — March 10, 2005 @ 9:01 am

  11. function category_vis_menu () {

    add_submenu_page(’edit.php’, ‘Category Visibility’, ‘Category Visibility’, 9, basename(__FILE__), ‘category_visibility’);

    }

    doing this will do. and will get rid of all the 404 errors

    Comment by TedFox — March 10, 2005 @ 9:34 am

  12. So after i managed to get rid of the 404, everything loads nicely into the SQL table. but when i try to save changes, i get the error

    Cannot load 5150.

    looking at the code. what’s a 5150 page?

    Comment by TedFox — March 10, 2005 @ 9:38 am

  13. TedFox — That was how I was calling the script back in the form. I guess now I need to figure out what to slip into the “action=” part of the plugin.

    Comment by Gudlyf — March 10, 2005 @ 9:43 am

  14. OK try the latest version I just put up (version 0.12).

    Comment by Gudlyf — March 10, 2005 @ 9:46 am

  15. I’m trying version 0.14 and getting the same 404. It seems to be looking for wp-admin/plugins/category_visibility.php. Should it be looking in wp-content instead?

    Comment by indi — March 10, 2005 @ 11:57 am

  16. sorry, think then talk. It was my upload problem.

    0.14 works perfectly for me now. Excellent idea. I was doing all kinds of things with the loop and various plugins to get this functionality, but this solution is clean and elegant.

    Comment by indi — March 10, 2005 @ 12:10 pm

  17. v0.14 works for me. Awesome! Really great plugin.

    Comment by charlie — March 10, 2005 @ 1:23 pm

  18. OK. It’s working, but there is a conflict with the plugin wp-wiki
    http://bakerstreetsystems.co.uk/WpWiki
    If I choose to hide anything which is in the wiki category from the front page, I get a 404 error when I click the permalink. If the post is on the front page, I click and it is fine. My permalinks are set in the format http://www.mysite/postname
    Hope you can help!

    Comment by charlie — March 10, 2005 @ 2:45 pm

  19. This works now ( v.14), but when I activate the plugin and view the page, the number of database queries jumps from 40 to over 500. This happens both on my main and test blogs, and drops back down if I turn off the plugin.

    Comment by Ian — March 10, 2005 @ 6:02 pm

  20. Hm… I bet I can get that number down. I’ll work on it tonight.

    Comment by Gudlyf — March 10, 2005 @ 6:52 pm

  21. How would I go about create a page in a sub directory for a specific category. For example, I want to be able to mark posts in a “private” category and then put that under /wordpress/private, secured using .htaccess. How would I go about doing this — from what I can tell this plugin only impacts the main frontpage? Thanks, sorry if this is vague I need to catch up on the possabilities a bit more …

    Comment by Bob — March 13, 2005 @ 11:32 pm

  22. This plugin looks interesting, and I’d like to extend it and test it, since cat visibility can allow for many other powerful plugins.

    Would you mind formally slapping a license on it? I’d like to get into the code, but don’t feel comfortable working on something without one. You’ll need one anyways if you want to toss it into wp-plugins.org

    Best,
    ~Tor

    Comment by Tor — March 14, 2005 @ 3:52 pm

  23. Tor — License added to the comments of the plugin. Please let me know what you wind up doing with it. I do want to lessen the number of database accesses, which I believe is due to the category list functionality.

    Comment by Gudlyf — March 14, 2005 @ 10:02 pm

  24. It won’t works for the sub-category under a parent? After i activated for the sub-category to “not showing on frontpage only” (it works for this function), but clicking on the sub-category list, the archive page for that category shows up with errors.

    Comment by Cara — March 14, 2005 @ 10:37 pm

  25. another problem, if a search with 0 results, i’ll get this:

    Warning: Invalid argument supplied for foreach() in /mysites/category_visibility.php on line 184

    Any ideas?

    Comment by Cara — March 15, 2005 @ 10:55 pm

  26. Cara — I fixed the 0 results problem in version 0.15. I haven’t had time to check out subcategories yet. Sorry.

    Comment by Gudlyf — March 16, 2005 @ 12:52 pm

  27. Hi, it works perfectly. Thank you. I really appreciate your help in solving this problem.
    As for the sub-categories, it’s ok, i’ll wait patiently. :-)

    Btw, you forgot to update the version no. in your post.

    Comment by Cara — March 17, 2005 @ 2:22 am

  28. Just want to point out, if you are using wpPaginate Plugin from Scriptygoddess while using the Category Visibility Plugins, there will be some problems with the page numbers.
    At least currently, it won’t show my last page (appear as 9 pages but actually should be 10 pages) thus my 1st few posts never shows up.

    I know nothing abt scripts, just want to point out the conflicts.

    Comment by Cara — March 17, 2005 @ 9:22 am

  29. I fixed another issue where this plugin was affecting what was listed in the admin management panel. Oops. Fixed now in 0.16.

    Comment by Gudlyf — March 17, 2005 @ 5:01 pm

  30. This is a great plugin that I would like to use for a site I am developing, but it has a glitch. It seems to still count the posts that are hidden from the front page in the total for the posts per page value. For example, if I had set WP to didplay 5 posts per page, and have my 5 most recent posts in a category that is not shown on the front page, I get a Sorry no posts found, until I click on the “next page” link.

    I have solved my problem with Ryan’s front-page-cats. plugin, but would prefer to use your more elegant solution…

    Comment by Philip Peeples — March 22, 2005 @ 1:33 pm

  31. Philip — I see what you mean. Unfortunately it looks like it may take more coding that I have time for right now to fix that, but I’ll keep looking at it.

    Comment by Gudlyf — March 22, 2005 @ 2:16 pm

  32. Great! I’ll keep my eye out for updates!

    Comment by Philip Peeples — March 22, 2005 @ 7:46 pm

  33. I agree with TedFox that it would be an even more fantastic addon if you could tie it to user levels. Seems a logical thing to do, but no one does it. And unfortunately it is beyond my abilities to hack it.

    Comment by Maxwell Smart — March 28, 2005 @ 4:25 pm

  34. I’m very interested in an update to this plug-in. Can we get an update on its status. It is looking like it will be very cool.

    Comment by Jesse Murphy — March 31, 2005 @ 1:18 am

  35. I have a wish feature.

    How about when you hide a category and its posts on the front page, it hides that category and its posts. Fine.

    But, how about if you hardlink a category (say a link in the header with a direct link to the category) that is hidden, it will still show a list of the posts in that category when you click the link? Right now, it just permanently hides the posts, but I need them still visible on a different page.

    Does that sound do-able?

    Comment by Michael Jones — April 1, 2005 @ 1:43 am

  36. But, how about if you hardlink a category (say a link in the header with a direct link to the category) that is hidden, it will still show a list of the posts in that category when you click the link? Right now, it just permanently hides the posts, but I need them still visible on a different page.

    This sounds similar to what I’m looking for.

    I have a category called WordPress that contains posts on plugins that I’m using or updates to the core software. I don’t really want these posts displayed on the front page or syndicated in RSS, but I’d still like people to be able to view them by clicking on the WordPress link in the Categories list.

    As it is now, if I hide a category from the front and RSS, and click on it in the category list, I get the message “Not Found”.

    Comment by Rich — April 5, 2005 @ 5:00 pm

  37. Rich — What you’re doing really should work - it works for me here (see the category “Photos”). Do you have the checkmark for “Archive” checked for your “Wordpress” category?

    Comment by Gudlyf — April 5, 2005 @ 10:28 pm

  38. OK guys, try the latest version now (0.18).

    Comment by Gudlyf — April 5, 2005 @ 10:44 pm

  39. This works pretty good, not on inherited categories tho.

    Comment by erikd — April 6, 2005 @ 8:52 am

  40. Try the latest version 0.21 for support with children categories. It’s not working for children of children, etc., but it should work if you’re only making single sub-categories and not sub-sub-categories. Sorry if that sounds confusing. Also made some improvements with the number of database lookups (I know that’s an issue for some people).

    Comment by Gudlyf — April 7, 2005 @ 1:35 pm

  41. I have the latest version.
    I have checked everything except FRONT in my catagory vis.

    I access the catagory and receive this error
    Sorry, no posts matched your criteria.

    Comment by Michael — April 7, 2005 @ 5:02 pm

  42. Does anyone else get this:
    1) after this plugin is enabled…
    2)… if new categories are defined…
    3).. the blug in has to be deactivated/activated again to see the new cats?
    t

    Comment by Timm — April 9, 2005 @ 12:23 pm

  43. There seems to be a conflict when both the WP-Googlestats and this plugin are activated. It works fine when activated alone, but when the WP-Googlestats plugin is also activated, clicking on “Category Visibility” or “Googlebot” under the “Manage” menu brings up the WP-Googlestats plugin. This is weird. I try manually entering /wp-admin/edit.php?page=category_visibility.php and it still brings up the WP-Googlestats page. Any Ideas?

    Comment by James Galvin — April 9, 2005 @ 3:38 pm

  44. Does your code use the wordpress database as having “wp_” prefix? Or does it use the wordpress’s global variable $wpdb? My wordpress database’s prefix is not “wp_”. I had to change it as I have more than one wp running on same db. Perhaps that could be why I’m stil getting the errors #2 ( comment ) states?

    Comment by David — April 10, 2005 @ 2:15 am

  45. Hi,

    I tried to use this and I have the issue where my WP site is looking for a table in the database. Am I supposed to run something to have the table created first?

    Thanks,
    md

    Comment by MD — April 10, 2005 @ 10:42 am

  46. Hey man - great plug-in … However, I had problems when I would use it with multiple installs of WP in one database - so, thanks to the help of the WP forums, I tweaked the code slightly (just by adding the $wpdb before each call to the table, so it creates a table with the wp_ (or whatever you set if for) prefix, which I think will eliminate the bugs I was having - which I’m pretty sure were only happening in databses with multiple installs … anyway, I’ll be happy to post it, email it to you, leave it for you to download, whatever - it’s your plug-in and all, so I figured I would just pass it on to you … (just a note, though - if you already have a table named cat_visibility, I had to drop it until the plugin would create the table - after that though, worked like a charm … and who knows, maybe even that is a quick and easy fix, it’s just beyond me, so … )

    Comment by Daniel — April 10, 2005 @ 11:27 pm


  47. cat_visibility = $table_prefix . 'cat_visibility';

    function category_vis_menu () {

    add_submenu_page('edit.php', 'Category Visibility', 'Category Visibility', 9, basename(__FILE__), 'category_visibility');

    }

    function category_visibility () {

    global $wpdb;

    if($wpdb->query("CREATE TABLE IF NOT EXISTS $wpdb->cat_visibility (
    cat_ID bigint(20) UNIQUE,
    front int(4) NOT NULL default 1,
    list int(4) NOT NULL default 1,
    search int(4) NOT NULL default 1,
    feed int(4) NOT NULL default 1,
    archives int(4) NOT NULL default 1
    )"));

    ?>

    3 ) : ?>

    ” method=”post”>

    Front: Visibility on the front/main page.
    List: Visibility on the list of categories on the home page.
    Search: Visibility in search results.
    Feed: Visibility in RSS/RSS2/Atom feeds.
    Archive: Visibility in archive links (i.e., calendar links).

    ” />

    get_results(”SELECT * FROM $wpdb->categories ORDER BY cat_name”);

    if ($categories) {
    foreach ($categories as $category) {
    if ($category->category_parent == $parent) {
    $category->cat_name = wp_specialchars($category->cat_name);
    $pad = str_repeat(’— ‘, $level);
    if ( $user_level > 3 ) {
    $catvis = $wpdb->get_results(”SELECT * FROM $wpdb->cat_visibility WHERE cat_ID=$category->cat_ID LIMIT 1″);
    $catvis = $catvis[0];
    if ($catvis->front == 1 || $catvis == 0) $catvis_front = “checked”; else $catvis_front = “”;
    if ($catvis->list == 1 || $catvis == 0) $catvis_list = “checked”; else $catvis_list = “”;
    if ($catvis->search == 1 || $catvis == 0) $catvis_search = “checked”; else $catvis_search = “”;
    if ($catvis->feed == 1 || $catvis == 0) $catvis_feed = “checked”; else $catvis_feed = “”;
    if ($catvis->archives == 1 || $catvis == 0) $catvis_archives = “checked”; else $catvis_archives = “”;
    $edit = “Front: cat_ID . “_front’ class=’edit’ type=’checkbox’ $catvis_front />  ”;
    $edit .= “List: cat_ID . “_list’ class=’edit’ type=’checkbox’ $catvis_list />  ”;
    $edit .= “Search: cat_ID . “_search’ class=’edit’ type=’checkbox’ $catvis_search />  ”;
    $edit .= “Feed: cat_ID . “_feed’ class=’edit’ type=’checkbox’ $catvis_feed />  ”;
    $edit .= “Archives: cat_ID . “_archives’ class=’edit’ type=’checkbox’ $catvis_archives />”;
    }
    else
    $edit = ”;

    $class = (’alternate’ == $class) ? ” : ‘alternate’;
    echo “$category->cat_ID$pad $category->cat_name
    $edit
    “;
    my_cat_rows($category->cat_ID, $level + 1, $categories);
    }
    }
    } else {
    return false;
    }
    }

    function edit_cat_vis () {

    global $wpdb;

    if (!$categories)
    $categories = $wpdb->get_results(”SELECT cat_ID FROM $wpdb->categories”);

    if ($categories) {
    foreach ($categories as $category) {
    $front = $category->cat_ID . “_front”;
    $list = $category->cat_ID . “_list”;
    $search = $category->cat_ID . “_search”;
    $feed = $category->cat_ID . “_feed”;
    $archives = $category->cat_ID . “_archives”;

    if ($_POST["$front"] == “on”) $front = 1; else $front = 0;
    if ($_POST["$list"] == “on”) $list = 1; else $list = 0;
    if ($_POST["$search"] == “on”) $search = 1; else $search = 0;
    if ($_POST["$feed"] == “on”) $feed = 1; else $feed = 0;
    if ($_POST["$archives"] == “on”) $archives = 1; else $archives = 0;

    $wpdb->query(”REPLACE INTO $wpdb->cat_visibility SET cat_ID=$category->cat_ID, front=$front, list=$list, search=$search, feed=$feed, archives=$archives”);
    }
    }

    }

    function alter_vis_posts ($posts) {

    global $wpdb, $wp_query;
    global $pagenow;

    /* If no posts for the selection, just return */
    if (!$posts)
    return;

    /* If we’re in the admin menu, return unfiltered */
    if ($pagenow == ‘edit.php’)
    return $posts;

    /* If table is empty, show all for now */
    if(!$wpdb->get_results(”SELECT cat_ID from $wpdb->cat_visibility”))
    return $posts;

    $visposts = array();

    $q = $wp_query->query_vars;

    /* Check if the category page itself should show posts */
    if (isset($q['category_name'])) {
    $cat_nicename = rtrim($q['category_name'], “/”);
    $cats = $wpdb->get_results(”SELECT cat_ID FROM $wpdb->categories WHERE category_nicename=’$cat_nicename’ LIMIT 1″);
    if($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    }
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$thiscat AND list=1″))
    return $posts;
    else
    return;
    }

    /* Check if archived pages should show posts */
    if(isset($q['year'])) {
    foreach ($posts as $post) {
    $categories = get_the_category($post->ID);
    $visible = 0;
    foreach ($categories as $category) {
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$category->category_id AND archives=1″))
    $visible = 1;
    }
    if ($visible == 1)
    array_push($visposts, $post);
    }
    return $visposts;
    }

    /* Check if search results should show posts */
    if (isset ($q['s'])) {
    foreach ($posts as $post) {
    $categories = get_the_category($post->ID);
    $visible = 0;
    foreach ($categories as $category) {
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$category->category_id AND search=1″))
    $visible = 1;
    }
    if ($visible == 1)
    array_push($visposts, $post);
    }
    return $visposts;
    }

    /* Continue with front page */

    foreach ($posts as $post) {
    $visible = 0;
    if($categories = get_the_category($post->ID)) {
    foreach ($categories as $category) {
    if(isset ($q['feed'])) {
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$category->category_id AND feed=1″)) {
    $visible = 1;
    }
    } elseif ($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$category->category_id AND front=1″)) {
    $visible = 1;
    }
    }
    } else
    $visible = 1;

    if ($visible == 1)
    array_push($visposts, $post);

    }

    return $visposts;
    }

    function alter_vis_catlist ($thelist) {

    global $wpdb;

    /* If table is empty, show all for now */
    if(!$wpdb->get_results(”SELECT cat_ID from $wpdb->cat_visibility”))
    return $thelist;

    if (preg_match(”/href/”, $thelist)) {
    $newlist = “”;
    $linklist = preg_split(’//’, $thelist);
    foreach ($linklist as $link) {
    $thiscatname = preg_replace(”/\s+\]*)?\>/”, “”, $link);
    $thiscatname = preg_replace(”/\.*/s”, “”, $thiscatname);
    $cats = $wpdb->get_results(”SELECT cat_ID from $wpdb->categories WHERE cat_name=’$thiscatname’ LIMIT 1″);
    if ($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$thiscat AND list=1″))
    $newlist .= $link . “\n”;
    }
    }
    return $newlist;
    } else {
    $thiscatname = $thelist;
    }

    $cats = $wpdb->get_results(”SELECT cat_ID from $wpdb->categories WHERE cat_name=’$thiscatname’ LIMIT 1″);
    if ($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    if($wpdb->query(”SELECT cat_ID FROM $wpdb->cat_visibility WHERE cat_ID=$thiscat AND list=1″))
    return $thelist;
    else
    return;
    } else {
    return $thelist;
    }

    }

    add_action(’admin_menu’, ‘category_vis_menu’);
    add_filter(’the_posts’, ‘alter_vis_posts’);
    add_filter(’list_cats’, ‘alter_vis_catlist’);

    ?>

    Comment by Daniel — April 10, 2005 @ 11:42 pm

  48. Arrgghh - sorry for the lengthy, weird looking posts - feel free to delete them, I was just trying to post the code in here for you … sorry …

    Comment by Daniel — April 10, 2005 @ 11:46 pm

  49. This is sort of working, but I get these error’s in the admin section:

    Warning: Cannot modify header information - headers already sent by (output started at /home/gr3909/public_html/articles/wp-content/plugins/category_visibility.php:293) in /home/gr3909/public_html/articles/wp-admin/admin.php on line 6

    Warning: Cannot modify header information - headers already sent by (output started at /home/gr3909/public_html/articles/wp-content/plugins/category_visibility.php:293) in /home/gr3909/public_html/articles/wp-admin/admin.php on line 7

    Warning: Cannot modify header information - headers already sent by (output started at /home/gr3909/public_html/articles/wp-content/plugins/category_visibility.php:293) in /home/gr3909/public_html/articles/wp-admin/admin.php on line 8

    Warning: Cannot modify header information - headers already sent by (output started at /home/gr3909/public_html/articles/wp-content/plugins/category_visibility.php:293) in /home/gr3909/public_html/articles/wp-admin/admin.php on line 9

    Can someone please clue me in as to how to fix that? I REALLY need to get this thing to work, thanks!

    -Pickled

    Comment by Pickled — April 11, 2005 @ 8:05 am

  50. I don’t get any errors using the plugin.. however, when i select a catagory on the menu which i have set as not to show on the main page, i’m told that there are no posts at all under that catagory. It seems to be compleatly filtering out everything that i don’t have showing on the front page.

    Comment by keaven — April 13, 2005 @ 3:48 pm

  51. Any updates related to comments #30/31 above?

    Comment by Philip Peeples — April 13, 2005 @ 8:26 pm

  52. Pickled - You likely have blank space at the beginning or end of your plugin codebefore or after th php opening or closing tags…delete that and you should be good to go.

    Comment by Philip Peeples — April 13, 2005 @ 8:28 pm

  53. so when i click on one of my categories that are set not to be visible on the main page (in other words - specifically selecting this category to see it’s posts) i get “sorry no posts matched your criteria” or some similar thing….is this the intended functionality?

    Comment by luke mueller — April 13, 2005 @ 10:30 pm

  54. am i missing something with the edit.php? and is the link for the plug-in for the category_visibility.php only or is the edit.php code in there as well, or am i not reading it through all the way…

    Comment by Jonathan — April 14, 2005 @ 4:39 pm

  55. very useful plugin. One thing I noticed is that invisible posts are still factored in to the ‘posts per page’. If I want 20 posts per page and 5 of them are invisible - only 15 will show up on the front page. I’m pretty sure, I mean, should test more extensively.

    Comment by indi — April 19, 2005 @ 6:21 am

  56. To the people that are commenting on the “sorry no posts matched your criteria” message when selecting a hidden category…

    I experienced the same behavior with this plugin. The solution was to enable permalinks. Once I did that it seemed to work as it should.

    The problem, however; is that enabling permalinks disabled some other functionality that I can’t live without, so I had to disable permalinks and discontinue my use of this plugin. I’m still hoping this will be resolved some day.

    Comment by Rich — April 19, 2005 @ 6:54 pm

  57. I activated your plugin but it seemed to be unable to create the database, so I copied the query from the code and manually created it. Now when I activate it I see this error (ten times!) on the front page:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND front=1' at line 1]
    SELECT cat_ID FROM cat_visibility WHERE cat_ID= AND front=1

    and no posts at all, only the Not Found page, though I didn’t choose to hide any category.

    Comment by maira — April 24, 2005 @ 12:01 pm

  58. Maira — ARe you using the latest development version of WP? I saw the error too, but it just started recently. It’s fixed in 0.25, but I’m hoping it won’t break anyone not using the development checkout of WP.

    Comment by Gudlyf — April 24, 2005 @ 10:05 pm

  59. Announcing Auto-TrackBack by Category Plugin for WordPress 1.5

    Here’s a little nugget for WordPress users. If you subscribe to a TrackBack aggregator like AustinBloggers, they want you to TrackBack all the posts you make that are relevant to that site, so that they can collect them for their audience. You can s…

    Trackback by Texas! Fight! — April 25, 2005 @ 5:33 pm

  60. True, I’m using one of the nightlies, I’m sorry I forgot to tell you. I installed the last version of your plugin (0.26) and that error dissappeared; however, I am unable to see the categories I hide from the front page though I have all the other options checked; if I click on their link or on the archives all I get is the not found page. The search is working, though.

    I’d love to have your plugin up and running, it’s something I’ve been looking for so long and yours is really complete. I specially like the user level option, which makes it very flexible. Many thanks for creating this and also for your support.

    Comment by maira — April 27, 2005 @ 5:17 am

  61. Another issue: i have one category invisible on the front page, all other options checked and user level set ot 1, but I can’t see its posts though I’m logged as admin. Tried with inherited categories and new (test) ones.

    Comment by maira — April 27, 2005 @ 5:27 am

  62. Well, I’ve tested what you say you have set, and it works for me. The fact you’re using nightlies doesn’t help, though. Try making sure you keep updated as it may be a bug you haven’t had fixed yet.

    Comment by Gudlyf — April 27, 2005 @ 9:50 am

  63. I get the following error repeatedly when i try to uncheck a setting:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    REPLACE INTO wp_cat_visibility SET cat_ID=1, front=1, list=1, search=1, feed=1, archives=1, user_level=

    Ideas?

    Comment by Steve — April 28, 2005 @ 10:54 am

  64. Try the latest code.

    Comment by Gudlyf — April 28, 2005 @ 11:09 am

  65. .27 the error isnt appearin on the options page, but now it appears on my site a whole bunch of times, to teh exclusion of all content

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND front=1 AND user_level

    Comment by Steve — April 28, 2005 @ 12:10 pm

  66. OK, try .28.

    Comment by Gudlyf — April 28, 2005 @ 12:17 pm

  67. Sorry..same error.

    Comment by Steve — April 28, 2005 @ 9:00 pm

  68. I get the same problem. Could it have something to do with subcategories?

    Comment by EmilV — May 1, 2005 @ 2:47 am

  69. In line ~238 the resulting SQL query is:
    “SELECT cat_ID FROM wp_cat_visibility WHERE cat_ID= AND front=1 AND user_level cat_ID is empty.

    Comment by EmilV — May 1, 2005 @ 2:51 am

  70. Firstly, I’m using WP 1.5 and the latest version of the Visibility plugin.

    When I upload the plugin file, it has an extension of .phps. When the file extension is left alone, the plugin DOES NOT show up in the list of available plugins. If I rename is to .php, it then shows up and allows me to activate it.

    When I activate it, I get the following errors on the main page of my blog:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND front=1 AND user_level

    Comment by Rev. Dubya — May 1, 2005 @ 5:45 pm

  71. Firstly, I’m using WP 1.5 and the latest version of the Visibility plugin.

    When I upload the plugin file, it has an extension of .phps. When the file extension is left alone, the plugin DOES NOT show up in the list of available plugins. If I rename is to .php, it then shows up and allows me to activate it.

    When I activate it, I get the following errors on the main page of my blog:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND front=1 AND user_level

    Comment by Rev. Dubya — May 1, 2005 @ 5:47 pm

  72. Please try version 0.29 and let me know if that works. It should default to user_level being zero…

    Comment by Gudlyf — May 2, 2005 @ 11:49 am

  73. No change with .29….

    Comment by EmilV — May 2, 2005 @ 12:30 pm

  74. Hello. I installed the plugin but i receive the following error when i load the home page:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND front=1 AND user_level

    Comment by Antonio — May 2, 2005 @ 1:54 pm

  75. It seems cat_ID is not delivered in the struct response from “get_the_category” (any more?) [I'm a newbie at this]. I tried replacing cat_ID with category_id in the lines 239 and 242 (v.29) and it worked like a charm. Now, I have no appreciation for the detailed workings of this script and maybe I introduce something really bad by making this change . I’d appreciate an expert opinion.

    Comment by EmilV — May 2, 2005 @ 3:33 pm

  76. “cat_ID” seems to be a change in the Wordpress nightlies. I made that change so it would continue to work for me, though in the process I may have messed things up for anyone still using version 1.5 — sorry about that. My guess with the problems people are having with the MySQL error is the line with ” AND user_level” in the code is getting chopped off, as the full line is ” AND user_level

    Comment by Gudlyf — May 2, 2005 @ 3:40 pm

  77. Hi, this is an excellent idea. I intend to use it in relation to the email publish option to allow users to email in their comments. But, to prevent spam posts, I want to use this to keep the Category off the frontpage.

    I am using version 0.29 of the plugin and WP version 1.5. It was a clean install a few days ago.

    I get the same error which has plagued everyone else and having read through the responses, there doesn;t seem to be a solution as yet. CAn you help?

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND front=1 AND user_level

    Comment by Alan — May 2, 2005 @ 7:13 pm

  78. Please try version 0.30. I’m sort-of winging it here, since this works fine for me. I took some whitespace out that may be causing the problem.

    Comment by Gudlyf — May 3, 2005 @ 10:01 am

  79. Still no joy. :( Same error.

    Comment by Alan — May 3, 2005 @ 2:06 pm

  80. I’m on WP 1.5 and CV 0.30.
    I got rid of my SQL errors by doing s/$category->cat_ID/$category->category_id/ inside alter_vis_posts().
    But then still won’t work. $user_levels is not set up correctly in alter_vis_posts(). It’s always NULL - whether I’m logged in or not. Does anyone else have the same problem? Or a clue to what’s going on?
    I looked up $user_level in in alter_vis_catlist() and there it /is/ properly set up.

    Comment by Mattias Päivärinta — May 7, 2005 @ 5:14 pm

  81. Please remove my comment spam above. Sorry about that :(
    Well, here is the patch that gets 0.30 going on 1.5 for me.

    --- category-visibility.php.old 2005-05-08 00:47:02.000000000 +0200
    +++ category-visibility.php.new 2005-05-08 00:48:34.000000000 +0200
    @@ -165,0 +166 @@
    + get_currentuserinfo();
    @@ -208 +209 @@
    - if($wpdb->query("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID AND archives=1 AND user_levelquery("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND archives=1 AND user_levelquery("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID AND search=1 AND user_levelquery("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND search=1 AND user_levelquery("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID AND feed=1")) {
    + if($wpdb->query("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND feed=1")) {
    @@ -242 +243 @@
    - } elseif ($wpdb->query("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID AND front=1 AND user_levelquery("SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND front=1 AND user_level

    Comment by Mattias Päivärinta — May 7, 2005 @ 6:00 pm

  82. I think I found a fix for your code. Looks like the get_the category function is not returning an data. I wrote a function in the top of your script to search the wp_post2cat table directly and changed the $category->catID lookups to $category->category_id..
    get_results("SELECT category_id from wp_post2cat where post_id = $postID");
    return $categories;
    }
    function category_visibility () {

    global $wpdb;
    global $cat_visibility;
    global $user_level;

    if (empty($user_level)) $user_level = 0;
    if (!is_numeric($user_level)) $user_level = 0;

    if($wpdb->query("CREATE TABLE IF NOT EXISTS $cat_visibility (
    cat_ID bigint(20) UNIQUE,
    front int(4) NOT NULL default 1,
    list int(4) NOT NULL default 1,
    search int(4) NOT NULL default 1,
    feed int(4) NOT NULL default 1,
    archives int(4) NOT NULL default 1,
    user_level int(4) NOT NULL default 0
    )"));

    ?>

    3 ) : ?>

    ” method=”post”>

    Front: Visibility on the front/main page.
    List: Visibility on the list of categories on the home page.
    Search: Visibility in search results.
    Feed: Visibility in RSS/RSS2/Atom feeds.
    Archive: Visibility in archive links (i.e., calendar links).
    User Level: Visibility on user level basis. All users up to this level can see posts as checked. Does not affect feed visibility, obviously.

    ” />

    get_results(”SELECT * FROM $wpdb->categories ORDER BY cat_name”);

    if ($categories) {
    foreach ($categories as $category) {
    if ($category->category_parent == $parent) {
    $category->cat_name = wp_specialchars($category->cat_name);
    $pad = str_repeat(’— ‘, $level);
    if ( $user_level > 3 ) {
    $catvis = $wpdb->get_results(”SELECT * FROM $cat_visibility WHERE cat_ID=$category->cat_ID LIMIT 1″);
    $catvis = $catvis[0];
    if ($catvis->front == 1 || $catvis == 0) $catvis_front = “checked”; else $catvis_front = “”;
    if ($catvis->list == 1 || $catvis == 0) $catvis_list = “checked”; else $catvis_list = “”;
    if ($catvis->search == 1 || $catvis == 0) $catvis_search = “checked”; else $catvis_search = “”;
    if ($catvis->feed == 1 || $catvis == 0) $catvis_feed = “checked”; else $catvis_feed = “”;
    if ($catvis->archives == 1 || $catvis == 0) $catvis_archives = “checked”; else $catvis_archives = “”;
    $catvis_user_level = $catvis->user_level;
    $edit = “Front: cat_ID . “_front’ class=’edit’ type=’checkbox’ $catvis_front />  ”;
    $edit .= “List: cat_ID . “_list’ class=’edit’ type=’checkbox’ $catvis_list />  ”;
    $edit .= “Search: cat_ID . “_search’ class=’edit’ type=’checkbox’ $catvis_search />  ”;
    $edit .= “Feed: cat_ID . “_feed’ class=’edit’ type=’checkbox’ $catvis_feed />  ”;
    $edit .= “Archives: cat_ID . “_archives’ class=’edit’ type=’checkbox’ $catvis_archives />  ”;
    $edit .= “User Level: cat_ID . “_user_level’ class=’edit’ type=’text’ size=’3′ value=’” . $catvis_user_level . “‘ />”;
    }
    else
    $edit = ”;

    $class = (’alternate’ == $class) ? ” : ‘alternate’;
    echo “$category->cat_ID$pad $category->cat_name
    $edit
    “;
    my_cat_rows($category->cat_ID, $level + 1, $categories);
    }
    }
    } else {
    return false;
    }
    }

    function edit_cat_vis () {

    global $wpdb;
    global $cat_visibility;

    if (!$categories)
    $categories = $wpdb->get_results(”SELECT cat_ID FROM $wpdb->categories”);

    if ($categories) {
    foreach ($categories as $category) {
    $front = $category->cat_ID . “_front”;
    $list = $category->cat_ID . “_list”;
    $search = $category->cat_ID . “_search”;
    $feed = $category->cat_ID . “_feed”;
    $archives = $category->cat_ID . “_archives”;
    $user_level = $category->cat_ID . “_user_level”;

    if ($_POST["$front"] == “on”) $front = 1; else $front = 0;
    if ($_POST["$list"] == “on”) $list = 1; else $list = 0;
    if ($_POST["$search"] == “on”) $search = 1; else $search = 0;
    if ($_POST["$feed"] == “on”) $feed = 1; else $feed = 0;
    if ($_POST["$archives"] == “on”) $archives = 1; else $archives = 0;
    $user_level = $_POST["$user_level"];

    if (empty($user_level)) $user_level = 0;
    if(!is_numeric($user_level)) $user_level = 0;

    $wpdb->query(”REPLACE INTO $cat_visibility SET cat_ID=$category->cat_ID, front=$front, list=$list, search=$search, feed=$feed, archives=$archives, user_level=$user_level”);
    }
    }

    }

    function alter_vis_posts ($posts) {

    global $wpdb, $wp_query;
    global $pagenow;
    global $cat_visibility;
    global $user_level;

    if (empty($user_level)) $user_level = 0;
    if (!is_numeric($user_level)) $user_level = 0;

    /* If no posts for the selection, just return */
    if (!$posts)
    return;

    /* If we’re in the admin menu, return unfiltered */
    if ($pagenow == ‘edit.php’)
    return $posts;

    /* If table is empty, show all for now */
    if(!$wpdb->get_results(”SELECT cat_ID from $cat_visibility”))
    return $posts;

    $visposts = array();

    $q = $wp_query->query_vars;

    /* Check if the category page itself should show posts */
    if (isset($q['category_name'])) {
    $cat_nicename = rtrim($q['category_name'], “/”);
    $cat_nicename = array_pop(explode(”/”, $cat_nicename));
    $cats = $wpdb->get_results(”SELECT cat_ID FROM $wpdb->categories WHERE category_nicename=’$cat_nicename’ LIMIT 1″);
    if($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    }
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$thiscat AND archives=1 AND user_levelID);
    $visible = 0;
    foreach ($categories as $category) {
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND archives=1 AND user_levelID);
    $visible = 0;
    foreach ($categories as $category) {
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND search=1 AND user_levelID)) {
    foreach ($categories as $category) {
    if(isset ($q['feed'])) {
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND feed=1″)) {
    $visible = 1;
    }
    } elseif ($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->category_id AND front=1 AND user_levelget_results(”SELECT cat_ID from $cat_visibility”))
    return $thelist;

    if (preg_match(”/href/”, $thelist)) {
    $newlist = “”;
    $children = 0;
    $linklist = preg_split(’/\t/’, $thelist);
    foreach ($linklist as $link) {
    if(preg_match(”/class.*children/”, $link)) {
    $children = 1;
    $newlist .= $link;
    } elseif(preg_match(”//”, $link) && $children) {
    $children = 0;
    $newlist .= $link;
    } else {
    $thiscatname = strip_tags($link);
    $thiscatname = preg_replace(”/\s+\(\d+\)\s+/”, “”, $thiscatname);
    $thiscatname = trim($thiscatname);
    if(!empty($thiscatname)) {
    $cats = $wpdb->get_results(”SELECT cat_ID from $wpdb->categories WHERE cat_name=’$thiscatname’ LIMIT 1″);
    if ($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$thiscat AND list=1 AND user_levelget_results(”SELECT cat_ID from $wpdb->categories WHERE cat_name=’$thiscatname’ LIMIT 1″);
    if ($cats) {
    foreach ($cats as $cat) {
    $thiscat = $cat->cat_ID;
    }
    if($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$thiscat AND list=1 AND user_level

    Comment by Adam Rose — May 7, 2005 @ 10:47 pm

  83. [...] 8212; Mattias @ 12:09 I går fick jag till begränsade kategorier i WP med category-visibility (0.30). Till en början skv&#2 [...]

    Pingback by några kråkor » Begränsade kategorier! — May 8, 2005 @ 6:11 am

  84. This plugin doesn’t produce any errors and works when I tell it to not show a catagory on the main page. However, I leave all the other boxes checked but it seems to have no effect. If I uncheck a box just so it doesn’t display under the main page, it doesn’t display anywhere. If they click on a catagory link or do a search it comes up with nothing. I didn’t even notice right away because I was so excited that it was working. Any thoughts as to why this happens?

    Comment by Tim — May 8, 2005 @ 8:40 am

  85. See the updated post notes above for a version that should work for non-nightly Wordpress 1.5.

    Comment by Gudlyf — May 9, 2005 @ 9:57 am

  86. [...] 29;gan om vilken nivå de ska ha. Nivå 0 vore det mest naturliga, tycker jag. Men category visibility gör ingen skillnad på icke [...]

    Pingback by några kråkor » Användarnivåer och category visibility — May 10, 2005 @ 4:19 am

  87. [...] rch 15th, 2005

    WP Plugin: Category Visibility

    I just installed the Category Visibility plugin for WordPress, and I must say that it& [...]

    Pingback by N. Godbout » Blog Archive » WP Plugin: Category Visibility — May 12, 2005 @ 8:37 am

  88. I would love to use this plugin, but when I click on “Category Visibility” on my menu, it shows me my ShoutBox administration page! The URL is edit.php?page=category_visibility.php, but I don’t actually see the controls.

    Comment by Matt — May 13, 2005 @ 9:33 am

  89. I installed the .31 version on a WP 1.5.1 install. I deselected a bunch of Archives boxes for a few categories. They poofed instantly. But the problem is that when I checked the boxes to bring the posts back, they stayed poofed. I checked the table and it is filled with ‘1’s’. So I’m not sure what the problem is.

    Comment by Troy — May 15, 2005 @ 6:36 pm

  90. If I uncheck Uncategorized from Front, and I click on a Page, there’s no copy on the page. It’s as if CV thinks a Page is Front, and a page is Uncategorized.
    Using 0.31, WP 1.5.1., revised Kubrick.

    Comment by Rich Hamilton — May 16, 2005 @ 10:20 am

  91. I installed the plugin and after few code edits (cat_ID and category_id) I was able to make it run without any errors and the disabled category does not show in front page (when turned off). However when I click on the category link it says “Not found”. It fails to find any posts within the marked category. Any suggestions on how to make this work. My version is .31-1.5

    Comment by Sudipta Bhawmik — May 18, 2005 @ 12:26 pm

  92. [...] couldn’t see my content (as it turns out, it was due to a plugin I was using called Category Visibility, and in all fairness, it was likely because I [...]

    Pingback by mechavox.com » Blog Archive » Can I get a "D’oh!" — May 19, 2005 @ 3:35 pm

  93. Just wanted to say: I’ve been thinking about how and why I wanted to hide categories, fiddled around with other plugs, even modified the loop to do it according to the WP-wiki, but wasn’t satisfied. Came across yours, plunked it in, and it fired up (WP 1.5.1.1). Conceptually simple, centralized management. It’s exactly what I’ve been looking for! Thanxabunch, Gudlyf!!!

    Comment by Tom — May 25, 2005 @ 7:48 pm

  94. Hi. I’m having the same trouble as Tim (comment #84). Posts that are checked to display as archives but not on the front page don’t display at all. What can I do to fix this? Thanks.

    Comment by Aja — June 2, 2005 @ 3:39 pm

  95. Good Plugin but I just want to remove visibilty from the front page ONLY not the whole catagory. Is there a fix?

    Comment by Fei — June 3, 2005 @ 12:03 am

  96. I solved my problem. Use this plugin instead…works like a charm. http://www.rummanddan.dk/archives/2005/03/hidden-category-plugin

    Comment by Fei — June 3, 2005 @ 12:39 am

  97. This plugin does not seem to work with WP 5.1.2. It produces many database errors.

    Comment by Avian — June 7, 2005 @ 7:35 pm

  98. Gizli Kategori

    Gudlyfi’s World adlı siteden yüklediğim Category Visibility adlı eklenti sayesinde, Kişisel kategorisine yazdığım yazılar ana sayfada gözükmeyecek. Böylece, sadece yakın çevremi ilgilendiren haberleri herkes okumak zorunda kalmayac…

    Trackback by tr.erinch.com — June 9, 2005 @ 7:30 am

  99. I got around the number-of-posts issue.
    Instead of picking out the visible posts out of 10 possible, I augment the select query via the posts_join and posts_where hooks.
    I’m neither 100% familiar with CV nor WP, so I’m not sure I nailed the code. But it does run fine over here.
    Replace alter_vis_posts() and its hooking up with this:

    function cv_posts_join($join) {
    . global $wpdb;
    . global $cat_visibility;
    . global $wp_query;
    . if (!isset($wp_query->query_vars['category_name'])) // Avoid collissionss
    . . $join .= ” LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id)”;
    . $join .= ” LEFT JOIN $cat_visibility ON ($wpdb->post2cat.category_id = $cat_visibility.cat_ID)”;
    . return $join;
    }

    function cv_posts_where($where) {
    . global $user_level;
    . global $wp_query;
    . global $cat_visibility;
    . global $pagenow;

    . /* If we’re in the admin menu, return unfiltered */
    . if ($pagenow == ‘edit.php’)
    . . return $where;

    . $q = $wp_query->query_vars;

    . get_currentuserinfo();
    . if (!is_numeric($user_level)) $user_level = -1;
    . $level_clause = “AND $cat_visibility.user_level

    Comment by Mattias Päivärinta — June 10, 2005 @ 3:37 pm

  100. Problems pasting code again :(
    Hope the rest comes through uncrippled.
    And sorry for the dots in the indentation above.


    function cv_posts_where($where) {
    global $user_level;
    global $wp_query;
    global $cat_visibility;
    global $pagenow;
    /* If we're in the admin menu, return unfiltered */
    if ($pagenow == 'edit.php')
    return $where;

    $q = $wp_query->query_vars;

    get_currentuserinfo();
    if (!is_numeric($user_level)) $user_level = -1;
    $level_clause = "AND $cat_visibility.user_level

    Comment by Mattias Päivärinta — June 10, 2005 @ 3:42 pm

  101. Here we go again…

    function cv_posts_where($where) {
    global $user_level;
    global $wp_query;
    global $cat_visibility;
    global $pagenow;
    /* If we're in the admin menu, return unfiltered */
    if ($pagenow == 'edit.php')
    return $where;
    $q = $wp_query->query_vars;
    get_currentuserinfo();
    if (!is_numeric($user_level)) $user_level = -1;
    $level_clause = "AND $cat_visibility.user_level

    Comment by Mattias Päivärinta — June 10, 2005 @ 3:47 pm

  102. wtf. im giving up.
    going to try a good old pingback instead.

    Comment by Mattias Päivärinta — June 10, 2005 @ 3:49 pm

  103. [...] [...]

    Pingback by Om Tova » Blog Archive » — June 11, 2005 @ 8:07 am

  104. Alright, so here is a bunch of them patches! Hope you like them.

    http://tova.fena.se/2005/06/11/category-visibility/

    Comment by Mattias Päivärinta — June 15, 2005 @ 5:20 am

  105. FANTASTIC !!!rnThis is the exactly i want…rnThanks, i will trackback in my blog.

    Comment by Neto Cury — July 7, 2005 @ 11:01 pm

  106. WORDPRESS PLUGIN CATEGORY VISIBILITY

    Há tempos procurava um plugin/hack que fizesse uma coisa simples, não mostrar na página principal (front page ou index) os posts de uma determinada categoria.nWORDPRESS PLUGIN CATEGORY VISIBILITYnn…

    Trackback by Neto Cury Blog — July 7, 2005 @ 11:44 pm

  107. I get this at the top of my page adn the script is not working, i dont know how to fix this, any suggestions. e-mail me please.rnrnrnrnWordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND front=1' at line 1]rnSELECT cat_ID FROM wp_cat_visibility WHERE cat_ID= AND front=1rnrnWordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND front=1' at line 1]rnSELECT cat_ID FROM wp_cat_visibility WHERE cat_ID= AND front=1rnrnWordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND front=1' at line 1]rnSELECT cat_ID FROM wp_cat_visibility WHERE cat_ID= AND front=1rnrnWordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND front=1' at line 1]rnSELECT cat_ID FROM wp_cat_visibility WHERE cat_ID= AND front=1rn

    Comment by Boris — July 12, 2005 @ 1:37 am

  108. Hi, this is a very neat plugin and would like to use it very bad. I tried and there were no problems at all. Just my query count went from 51 to 180!rnHow can I lower this?

    Comment by Danny — July 15, 2005 @ 3:19 am

  109. Danny, you could check out my patches. Specifically my second patch will make a big difference I think.rnOr you could try out the Elegant Category Visibility plugin. That one does not support the user level restriction however, which is why I’m sticking with this one.

    Comment by Mattias Päivärinta — July 19, 2005 @ 5:23 am

  110. I can’t get the plugin working with feeds on wordpress 1.5.2 - it just shows all posts, regardless of settings.

    Comment by John — July 24, 2005 @ 3:46 am

  111. Great plugin. I just installed it and I don’t think there are any problems. In fact, I just used it for the first time. It’s great because there are some things that I need to get off my chest once in a while bu that just don’t belong out there for anybody to see. I just like being able to post things for myself. And it’s nice to know that since it makes things completely invisible… someone who for some weird reason might want to hack and see what I wrote wouldn’t even know there was anything to hack in the first place. Great job and great plugin. Awesome!

    Comment by Eric — July 25, 2005 @ 11:00 pm

  112. Just wanted to say: I’ve been thinking about how and why I wanted to hide categories, fiddled around with other plugs, even modified the loop to do it according to the WP-wiki, but wasn’t satisfied. Came across yours, plunked it in, and it fired up (WP 1.5.1.1). Conceptually simple, centralized management. It’s exactly what I’ve been looking for! Thanxabunch, Gudlyf!!!

    Comment by 8thstreetlatinas — August 11, 2005 @ 9:12 am

  113. global $wpdb;
    global $cat_visibility;
    global $user_level;

    if (empty($user_level)) $user_level = 0;
    if (!is_numeric($user_level)) $user_level = 0;

    if($wpdb->query(”CREATE TABLE IF NOT EXISTS $cat_visibility (
    cat_ID bigint(20) UNIQUE,
    front int(4) NOT NULL default 1,
    list int(4) NOT NULL default 1,
    search int(4) NOT NULL default 1,
    feed int(4) NOT NULL default 1,
    archives int(4) NOT NULL default 1,
    user_level int(4) NOT NULL default 0

    Comment by Streetblowjobs — August 12, 2005 @ 6:00 am

  114. Danny, you could check out my patches. Specifically my second patch will make a big difference I think.rnOr you could try out the Elegant Category Visibility plugin. That one does not support the user level restriction however, which is why I’m sticking with this one.

    Comment by 8thstreetlatinas — August 14, 2005 @ 5:39 am

  115. Hi,

    The plugin works ok on my 1.5.3 install, but when i untick the FRONT tick box for a given category, it removes all articles in that category from every page, not just the home page. If i view by category and choose a category that has the front tick box unticked, then the category view for that shows NO ARTICLES !!!!

    Is there something i am doing wrong ?

    Olly

    Comment by Oliver Marshall — August 17, 2005 @ 5:18 am

  116. . $q = $wp_query->query_vars;

    . get_currentuserinfo();
    . if (!is_numeric($user_level)) $user_level = -1;
    . $level_clause = “AND $cat_visibility.user_level

    Comment by Camcrush — August 18, 2005 @ 10:12 am

  117. Hi,
    i use cat-visibility plugin on one of my WP pages and in works perfect (WP ver. 1.5.1).

    I tried it on another page (WP ver. 1.5.1.2) and I’ve got 404 error when accessing post in category that has all - except archive visibilities off.

    It should show the post like on my v.1.5.1 page - but it does not show?

    What should I check?

    ps. my 1.5.1 page
    and 1.5.1.2 page (Polish only, sorry)

    Comment by dan — August 19, 2005 @ 4:47 pm

  118. Any chance the bug described in comment #90 [Pages being excluded if the default cat is NOT shown on front] will be addressed?
    Thanks.

    Comment by Moshu — August 31, 2005 @ 10:22 am

  119. Unfortunately I don’t have time these days to provide updates. My *plan* is to release complete updates to my plugins once WP 1.6 is released. Sorry you’ll have to wait so long. However, if anyone wants to update my code and hand it over to me to host here, I’ll be glad to consider it.

    Comment by Gudlyf — August 31, 2005 @ 1:01 pm

  120. Minor Updates

    Been doing some minor updates that are worth mentioning…

    Trackback by daniel-lim.co.uk — September 4, 2005 @ 8:01 am

  121. [...] Next up is another Guff plugin, Category Visibility. I grabbed this so I could post announcements like this one, but not have them show up on the front page. [...]

    Pingback by tylerwillis.com - added a few more plugins — September 8, 2005 @ 5:49 pm

  122. [...] Edit: I have just installed a wordpress Plugin which would tempoarily remove any material deemed to be against the law on sept 17th, if it is illegal. [...]

    Pingback by Morph | Blog NZ » Blogs on Election Day — September 15, 2005 @ 12:44 am

  123. I have made a bunch of updates to the plugin and made a patched version available at my site.

    Please Keith, take my updates into consideration.

    Comment by Mattias Päivärinta — September 15, 2005 @ 7:52 am

  124. Using .31 of your plugin and wp 1.5.2. activated the plugin and now nothing shows up anywhere no matter what i check or uncheck. deactivated the plugin and still nothing shows up! what am i doing wrong?

    Comment by mm — September 17, 2005 @ 5:04 pm

  125. oops. it seems to be a problem with my theme. very sorry. * blush*

    Comment by mm — September 17, 2005 @ 5:07 pm

  126. For those who want articles to appear on category pages but not the front page. In version 3.1, beneath line 238:

    /* Continue with front page */

    I added:

    if ($_REQUEST[cat] || $_REQUEST[p]) {
    $frontcheck = “”;
    } else {
    $frontcheck = “AND front=1 “;
    }

    Then, what is now line 253:

    } elseif ($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID AND front=1 AND user_levelquery(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID $frontcheck AND user_level

    Comment by Jerry — September 22, 2005 @ 12:04 am

  127. Hm. Line 253 is mangled in the above post. It should be:

    } elseif ($wpdb->query(”SELECT cat_ID FROM $cat_visibility WHERE cat_ID=$category->cat_ID $frontcheck AND user_level

    Comment by Jerry — September 22, 2005 @ 12:05 am

  128. [...] So it turns out that Ryan Poe’s Category (in)Visibility plugin had a bug: Page entries were always hidden while it was active. Keith McDuffee’s Category Visibility didn’t have that bug, but it did prevent invisible entries from being visible through their specific category links. [...]

    Pingback by Crabby Night Owl » Blog Archive » Category Visibility, Revisited — October 11, 2005 @ 4:46 am

  129. Another issue: i have one category invisible on the front page, all other options checked and user level set ot 1, but I can’t see its posts though I’m logged as admin. Tried with inherited categories and new (test) ones.

    Comment by street sex — October 11, 2005 @ 10:33 am

  130. in few words… impressive!, it’s just a great plugin. i’ve looking for something like this by several days and your great plugin is the solution to my problems (at least referring to wordpress’ related :D)

    Thank you so much.

    Comment by Tapanez — October 15, 2005 @ 2:49 pm

  131. [...] category visibility and solvent: we all have posts we’d rather not have people stumbling across by accident, like the ones where you try your hand at composing cheeky petrarchan sonnets or the ones where you spew your heart out to your ex and say what you really think about them. save some face: category visibilty lets you choose whether or not you want your posts to show up on the front page, side bar, search results, rss feed, or archives. solvent conveniently lets you mark your post as slippery so it won’t show on the front page. worries that people will find out just how bad your poetic attempts are and plaster them all over the internet will fly out the window! [...]

    Pingback by swell » ..:: plug-in madness (@_@) — October 22, 2005 @ 3:41 am

  132. AWESOME PLUGIN!!! Thank you so much for figuring out this problem :)

    Comment by Par Triv — October 22, 2005 @ 6:39 pm

  133. Unless I allow something to show up on the FRONT check box, the archive link doesn’t work (yes I have archive checked in the CV)…. any ideas? Thnx.
    WP 1.5
    CV .31

    Comment by Par Triv — October 22, 2005 @ 6:50 pm

  134. UPDATE, if I have only LIST and ARCHIVE checked, the archive links work, but I want only want archive checked, not list (or front). Thanks.

    Comment by Par Triv — October 22, 2005 @ 6:52 pm

  135. Are you still working on this plugin, I dare not try something that is “very much in beta”. This post spawns from March 8th, 2005 which is quite a while ago. Otherwise I must say: GREAT IDEA! So, are there plans for a non-beta version?

    Comment by Kent Larsson — October 24, 2005 @ 10:55 am

  136. I don’t have much time these days to work on the plugins, unfortunately. I do have it in the back of my head to update this plugin and the AuthImage plugin once the next big release of WordPress comes out. Until then, I don’t want to spend a lot of time trying to fix bugs if the new WP release is just going to crop up a whole mess of new bugs I’ll need to fix.

    Comment by Gudlyf — October 24, 2005 @ 10:59 am

  137. Thanks for your swift answer! I hope that WordPress doesn’t break the previous API for quite a while, but perhaps it will happen in the next major release. I’ll try to code something similar to this myself when I get enough time,I’ll start from scratch though so it might never get done. ;) Have a nice life! Bye.

    Comment by Kent Larsson — October 24, 2005 @ 1:10 pm

  138. [...] Ein neues Plugin wurde installiert: CategoryVisibility. Ermöglicht es, Kategorien auf bestimmten Ebenen aus- bzw. einzublenden. So wird z.B. die Kategorie ‘del.icio.us’ nicht mehr auf der FrontPage dargestellt. blog Changelog plugin wordpress [...]

    Pingback by WordPressing » Blog Archive » Plugin: Category_Visibility — October 26, 2005 @ 5:43 am

  139. This is a GREAT plugin! It’s the total answer to my problem, and much more. Thanks so much.

    Comment by Lance Brown — December 23, 2005 @ 12:38 am

  140. I love this plugin, thank you :)
    Happy new year ^_^

    Comment by Kenzo — December 25, 2005 @ 3:30 am

  141. [...] Gudlyf’s World » Wordpress Plugin: Category Visibility This plugin adds a new menu link under the “Manage” admin menu titled “Category Visibility”. (tags: wordpress plugin category visibility) [...]

    Pingback by links for 2006-01-03 at Salted Lolly — January 4, 2006 @ 1:17 pm

  142. Hi…
    Here is my small hack to fix the Permalink error:
    Go to the line ~195 a look for:
    $cat_nicename = array_pop(explode(”/”, $cat_nicename));
    remove and change it to (2 lines):
    $cat_nicename = explode(”/”, $cat_nicename);
    $cat_nicename = array_pop($cat_nicename);
    Have fun ;)

    —–
    Kenzo
    Webmaster: http://dreamgirls.pandela.org/

    Comment by Kenzo — January 8, 2006 @ 6:20 am

  143. Thanks for the plugin … It appears to work OK on 2.0 btw, I added it to the list

    http://codex.wordpress.org/User:Matt/2.0_Plugin_Compatibility

    cheers

    Comment by Patrick B — January 9, 2006 @ 5:50 pm

  144. I have the same problem as Par_Triv (133 & 134): FRONT check box works always, but the rest of boxes — works in a strange ways (if they decided to work). “Feed” option works only sometimes, for example.

    Comment by pvp — January 11, 2006 @ 5:33 pm

  145. I take it that this plugin does not work with Wordpress 2.0 :(

    Will there be an update soon??

    Comment by Robert Shea — January 12, 2006 @ 10:52 am

  146. is there this pluin for wp2 ?

    Comment by Dell — January 27, 2006 @ 3:42 pm

  147. [...] Category Visibility - este é mais completo, possui opções para a index principal, lista de categorias, busca e feed. [...]

    Pingback by Portal WordPress » Blog Archive » VISIBILIDADE DE CATEGORIAS — January 28, 2006 @ 10:18 am

  148. I have two hidden categories, based on user level 1 and from the feed. I have one static page, this become hidden as well. Bug? Forgotten something? I have WP 2.01.

    Comment by Stat — February 2, 2006 @ 4:27 am

  149. Just tested this out, and it *does* work on WP 2.0.1 :)

    … and it just saved me a butt-load of trouble for my new design. Great work. Can’t wait to see the post count-issue fixed, but I can definitely live with it for now. :)

    Comment by Andy — February 2, 2006 @ 3:55 pm

  150. Hi, I am using this plugin with WP 2 and it works great but I have a question.. What user level should I use just so that registered users can see certain Category?

    Comment by Jason — February 5, 2006 @ 7:19 pm

  151. I’ve noticed this plugin causes problems with permalinks in WP2.0 Has anyone else experienced this problem? If so, is there a fix?

    Comment by Steve — February 8, 2006 @ 3:53 am

  152. I modified Keith’s Category Visibility plugin somewhat for WP 2.0x.

    I fixed the number of posts thing. And I believe the 2.0 permalinks problem is resolved. And a few other gotchas, like adding a new category but forgetting to go to CV to set the userlevel.

    If you want to give it a try it’s at http://ryowebsite.com/?p=46

    Comment by Rich — February 15, 2006 @ 5:02 pm

  153. Hi.

    I would just like to tell you your plugin works great for me in wordpress 2.0

    The only thing i noticed is that when I add a new category from the “New Post” page, I have to go to the “Category Visibility” page and set the user level for the new category, or else the new category won’t be visible. It would be nice if the new category was visible by default, but I can live with it.

    Good stuff.

    Comment by Soccer Clips — March 3, 2006 @ 12:37 pm

  154. How can I avoid that the plugin also stops the “pages” of the blog?

    For me is very important!

    Thanks!

    PS: excuse for my English…

    Comment by andryonline — March 18, 2006 @ 5:49 am

  155. Hi, I’m having some errors during the configuring phase of wordpress plugin Category visibility. When I click on Category Visibility Button I have this kind of error (for 4 times):

    WordPress database error: [You have an error in your SQL syntax near 'LIMIT 1' at line 1]
    SELECT * FROM wp_cat_visibility WHERE cat_ID= LIMIT 1
    If I try to uncheck a visibility for a categories of mine, I have many of the following error:
    WordPress database error: [You have an error in your SQL syntax near ' front=1, list=1, search=1, feed=1, archives=1, user_level=0' at line 1]
    REPLACE INTO wp_cat_visibility SET cat_ID=, front=1, list=1, search=1, feed=1, archives=1, user_level=0.

    Am I missing anything ?

    Thanks
    Antonio

    Comment by guastatore — March 28, 2006 @ 5:31 am

  156. [...] I got hold of a Wordpress plugin called “Category Visibility” version 0.31 by Keith McDuffee which was written for WordPress 1.5.   It seems that  no updates where made  for WordPress 2.x  and the search continued.   There was a  comment posted on the above listed website  that linked to  an updated  version.  It works very nice! [...]

    Pingback by warnich.rust.co.za » Blog Archive » How to make certain categories in WordPress not show up on the front page — April 6, 2006 @ 4:44 pm

  157. [...] I’ve used a plug-in category_visibility by Keith McDuffee, to achieve this technical trickery. [...]

    Pingback by Robert Sharp » Blog Archive » Amnesty Category — April 28, 2006 @ 6:31 pm

  158. This plugin worked great on WP 1.5, but it broke my feed in 2.0.x. Looking forward to the update.

    Comment by Ryan — June 4, 2006 @ 6:35 pm

  159. [...] For those who are curious, I’m using the built-in RSS widget to handle favorites, text widgets to handle the “About” and “Technorati” sidebar entries, and the Sideblog Plugin and widget to handle the “Asides.”  This enabled me to dump all kinds of custom code which I had hacked into WordPress and the theme.  I was also able to stop using Category Visibility (which, while nice, takes a bit of tweaking whenever one adds a new category).  In addition, version 2 of the veryplaintxt theme added options like justifying the sidebar differently, which was great because along with its widget support I now have absolutely no reason to hack the theme at all.  I can just upgrade and not worry (theoretically), or change themes and not worry, as long as the new theme supports widgets. [...]

    Pingback by Talking Out Of Turn » Blog upgrades — June 9, 2006 @ 4:43 pm

  160. Items from an invisible category show up in teh Next / Prev Item links. Otherwise the items disappear altogether and dont cause an embarrassment. How to fix this?

    Comment by Subir Ghosh — June 10, 2006 @ 6:53 am

  161. You rule! I love this pluggin

    Comment by Emi — July 31, 2006 @ 10:25 am

  162. Hey thanks for this kickass plugin. I was stressing about unchecking the visible at front attribute producing a blank post instead of content. Fortunately, such a problem became a huge feature! My site has tutorials as well as news. I wanted these content feeds separate for the user. What I’ve done was created a tutorials page with tutorial post links and a tutorials category. I unchecked the list attribute for the tutorials category. Now traffic, wanting to see the list of tutorials will be diverted to a page list I’ve made instead of a category with all media content loaded! My tutorials will have lots of images and video, so you’d wonder how I’d prevent them from loading on the main page? I use the tag directly below my intro paragraph. This not only cuts the media from loading on the main page, but notifies users about the new tut. Thanks for this!

    Comment by Matt Vogt — August 20, 2006 @ 6:03 pm

  163. I’m on WP 1.5. I tried:
    http://www.gudlyf.com/media/category_visibility-wp1.5.phps
    and
    http://www.gudlyf.com/media/category_visibility.phps (.31)
    And both caused db errors. The first one caused errors on the admin side, the second one caused errors on the public side.

    Comment by Ryan Walker — September 29, 2006 @ 3:55 pm

  164. [...] Rich Hamilton’s revision of Keith McDuffee’s original “Category Visability” is an excellent WP plug-in. It just doesn’t quite work the way I needed for the main Moshav HaAm site, which has relatively sophisticated needs for layers of content access, given our mandate to be as open as possible to a number of different valences of community and leadership. [...]

    Pingback by Moshav HaAm Lab » Blog Archive » WordPress Category Visability Hack — November 15, 2006 @ 2:20 pm

  165. This plugin appears to do most of what I would like it to do with one exception: I have the need for a subcategory to not only not show up on the main page but also not show up under the main category page as well.

    i.e.,

    Plants
    +–general information
    +–hints

    This is not what I’m using but simply an example. In this case I wouldn’t want hints showing up under the category posts since hints would be a specific thing to look up and not something desired as a regular post. I would only want it showing up when the user specifically selects the hints subcategory.

    I understand that may be a bit out of the ordinary but, in my case, very necessary.

    Regards, Veg

    Comment by Veg — November 25, 2006 @ 10:42 pm

  166. HI!! :)

    I recently downloaded your plugin today; however i am having problems with it. When I go to ‘Manage’ it doesn’t show me any options for the catagory visibility plugin. I’m not sure what i’m doing wrong. I have Owen Winkler’s “role manager” and i have the latest version of wordpress (20.5). Any help would be appreciated!! :)

    Thanks again, for a wonderful plugin!

    Comment by Julie — December 11, 2006 @ 10:33 am

  167. [...] Category Visability Hack Rich Hamilton’s revision of Keith McDuffee’s Category Visability is an excellent WP plug-in. It just doesn’t quite work the way we need for the new Moshav [...]

    Pingback by Yeshivat Simchat Lev » WordPress Category Visability Hack — May 1, 2007 @ 10:33 pm

  168. [...] quite happy with the upgrade. I have a couple of small hiccups and found a plugin that I couldn’t get to work. Luckily it was a minor plugin. Otherwise, no problems with the [...]

    Pingback by Please Let Me Know If You Find A Problem... - Dawud Miracle @ dmiracle.com - (formerly Healthy WebDesign) — May 31, 2007 @ 7:46 am

  169. There some difference between this plugin and http://codex.wordpress.org/Plugins/Restriction Categories2Plugin

    Comment by likevoodoo — June 9, 2007 @ 6:34 am

  170. I would like to have how default all the categories
    hidden;
    can you suggest which is the cahnge that I must to do?

    Now by default in admin all the categories are
    checked and if you remove checked you can
    hidden categories;

    I would like to have the opposite:
    I think there are two solutions:
    -1 by default if all is checked then the categories
    are hidden and if I remove check I can see it;
    or
    2 by default all isn’t checked and I not see
    categories; only if I check I see categories;

    I think found the parameter for to change but
    have always problem that if one click same time button submit changes all checked switch at every
    click;
    can help

    Comment by robs — September 19, 2007 @ 10:09 am

  171. Looking for 2.3 support visit iPeat.com

    Comment by iPeat — March 11, 2008 @ 4:43 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)