• I’m filtering some posts, and it’s working fine in the from end, but it’s also filtering the posts in the admin, which I don’t want.

    Here is some example code of what I’m trying to do, and the ??? is where I’m stuck

    add_filter('the_posts', 'my_function' , 1 );
    
    function my_function( $posts ) {
    
        //
        // Check to see if we are logged into the admin panel
        //
        if (???) {
            return $posts;
        }
    
        //
        // If we are not in the admin, filter the posts
        //
    
        // create an array to hold the posts we want to show
        $new_posts = array();
    
        //
        // loop through all the post objects
        //
        foreach( $posts as $post ) {
    
            $include = true;
    
            //
            // Perform Filter comparison
            //
            if ($filterPost>=1) {
                $include = false;
            }
    
            //
            // if we want to include it then
            // add the post object to the new posts array
            //
            if ( $include === true ) {
                $new_posts[] = $post;
            }
        }
    
        //
        // send the new post array back to be used by WordPress
        //
    	return $new_posts;
    }
Viewing 1 replies (of 1 total)
  • Thread Starter laqrhead

    (@laqrhead)

    Well, I’ve come up with a dirty hack, but maybe it’s the only way? I’m checking for the wp-admin folder in the URL. I don’t know why someone would change the admin folder, but if they did, this wouldn’t work.

    if (stristr($_SERVER['SCRIPT_URI'], 'wp-admin') !== FALSE) {
        return $posts;
    }

    If anyone knows of a better way please let me know.

Viewing 1 replies (of 1 total)
  • The topic ‘How do you check whether a request is from the admin panel?’ is closed to new replies.