Title: PHP Warning: Undefined array key &#8220;post_type&#8221; in class-backend.php
Last modified: September 4, 2026

---

# PHP Warning: Undefined array key “post_type” in class-backend.php

 *  [Daniel Chase](https://wordpress.org/support/users/riseofweb/)
 * (@riseofweb)
 * [3 days, 19 hours ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-post_type-in-class-backend-php/)
 * **Environment:**
    - WordPress 7.1
    - PHP 8.3.33
    - WooCommerce 11.0.1
    - Server: Apache
 * **Description:**
 * Getting the following warning in the logs:
 *     ```wp-block-code
       PHP Warning: Undefined array key "post_type" in [site]/wp-content/plugins/search-exclude/lib/controllers/class-backend.php on line 173
       ```
   
 * **Cause:**
 * Line 173 reads `$_REQUEST['post_type']` directly without checking whether the
   key exists first:
 * php
 *     ```wp-block-code
       public function save_post_ids_to_search_exclude( $post_ids, $exclude ) {
           $post_type = $_REQUEST['post_type'];
       ```
   
 * On PHP 8.0+, accessing an undefined array key raises a warning instead of silently
   returning `NULL` (as it did on PHP 7.x). Since `save_post_ids_to_search_exclude()`
   is presumably being called (directly or via a hook) in a request that doesn’t
   include a `post_type` parameter, this fires every time.
 * **Suggested fix:**
 * Use `isset()` with the null coalescing operator so it degrades gracefully when`
   post_type` isn’t present:
 * php
 *     ```wp-block-code
       $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
       ```
   
 * (Adding `sanitize_key()` here too, since this is unsanitized `$_REQUEST` input
   being used as an array key shortly after.)
 * **Impact:**
 * Cosmetic/log-noise only in my case so far — doesn’t appear to break functionality—
   but it’s worth fixing since PHP is trending toward stricter handling of undefined
   array access in future versions, and it clutters error logs on sites with logging/
   monitoring enabled.

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-warning-undefined-array-key-post_type-in-class-backend-php%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/search-exclude/assets/icon-256x256.png?rev=2916925)
 * [Search Exclude](https://wordpress.org/plugins/search-exclude/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/search-exclude/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/search-exclude/)
 * [Active Topics](https://wordpress.org/support/plugin/search-exclude/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-exclude/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-exclude/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Daniel Chase](https://wordpress.org/support/users/riseofweb/)
 * Last activity: [3 days, 19 hours ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-post_type-in-class-backend-php/)
 * Status: not resolved