• Hello,
    I’m writing aplugin that im trying to filter out posts from the loop via certain if.

    function add_my_stuff($title)
    {
    global $wpdb;
    global $post_privacy;
    global $id;
    global $authordata;
    global $postdata;
    global $post;

    if ($post_privacy->privacy == “private”) {

    $title = “Private Post”.$content;

    }
    return $title;
    }

    add_filter(‘the_title’,’add_my_stuff’);

    this works perfect, But i wish to completly wipe out the post from the loop and not just alter it.
    How can i do that?, I searched the hooks and i didnt find anything.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Without completely understand what you’re after, it sounds similar (conceptually) to this Category Visibility plugin: http://ryowebsite.com/?p=46

    Maybe have a look at that one and see how he does it?

    Thread Starter aloncarmel

    (@aloncarmel)

    Hey, thanks for the link.
    What i want todo is remove a certain post that equales the IF i did from the query loop. Not just changing the title like i did now.

    I understood i need to use the_posts hook for the filter but i need to return to the array some how i dont understand how.

    Well, the lazy way would be to add the private posts to a category (perhaps “Private” would make sense?) and then use the plugin I showed to filter ’em out.

    I know that’s not as much fun as making your own 😉 but it’s an approach.

    If that’s truly missing the mark, perhaps a coder type will spot this thread and offer some ideas.

    Thread Starter aloncarmel

    (@aloncarmel)

    i am tagging the private posts already with a plugin of my own. I can filter out the ones that i marked as public or private. but i dont know how to alter the array query of the posts so that they wont be calculated in the loop in the firstplace. i manage to remove post_link and such but i understood i need to use posts_where or the_posts in the filter. but i need to return an array filtered and i dont know how.

    Ah. I begin to understand. I don’t have the answer, but you might look over the code in that first link I gave you. I know he does handle that exact same scenario.

    Thread Starter aloncarmel

    (@aloncarmel)

    anyone might know?

    Why don’t you just collect the post_ID on the private posts in an array like this:

    $res = $wpdb->get_results(“SELECT ID FROM $tableposts WHERE status = ‘private”);

    if(have_posts(): while(have_posts(): the_post()){
    if(!in_array(the_id(), $res->ID){
    //do your stuff
    }
    }

    Or similar…

    Thread Starter aloncarmel

    (@aloncarmel)

    because im not refering to the regular private. for each post i added a value for private global posts and global public posts.
    whats not working ?

    function filterbugs($where){
    global $wpdb;
    global $bug_meta;
    global $id;
    global $authordata;
    global $postdata;
    global $post;

    if ($bug_meta->privacy == ‘private’); {
    $where .= “”;
    return $where;
    }

    }
    add_filter(‘posts_where’,’filterbugs’);

    it gets the whole list scambled and massed up. how can i return an empty $where to the posts_where.
    I manage to whip out a post with a certain title but i dont need to whip with a certain title because i already know the post status with a global $bug_meta

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Filtering loop query’ is closed to new replies.