WordPress.org

Ready to get started?Download WordPress

Forums

the_posts hook problem (1 post)

  1. realwx
    Member
    Posted 7 years ago #

    I can't get this plugin working. The main object of this plugin is to block guests from viewing any post in a set category via plugin file. I've set category number as 1. This is my first plugin, so don't yell at me!

    <?php
    /*
    Plugin Comments removed for posting on WordPress.org
    */

    $my_cat = "1";

    function applysubbyposts($the_posts) {
    global $wpdb;
    if(!is_user_logged_in()) {
    foreach($the_posts as $key => $post) {
    $thiscat = $wpdb->get_var("SELECT category_id FROM post2cat WHERE post_id='$post->ID'");
    if(floatval($thiscat) == floatval($my_cat)) unset($the_posts[$key]);
    }
    }
    return $the_posts;
    }
    add_filter("the_posts", "applysubbyposts");
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic