is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)

Open Beginner friendly
#1,041 1 comment 0 reactions 0 assignees View on GitHub

@faisalahammad is already working on this.

Since Oct 12, 2026.

  • #1049 by @faisalahammad — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Start in includes/revisions.php at acf_revisions::acf_validate_post_id() and review its acf/validate_post_id hook and early preview check. Reproduce the plugins_loaded get_field() call with WP_DEBUG enabled, then verify that early reads no longer log the is_preview notice while normal preview validation remains intact.

Written by the indexing model from the issue text.

Description

is_preview was called incorrectly notice on every early get_field() since 6.8.10

Environment
  • ACF PRO 6.8.10
  • WordPress 7.0 (multisite)
  • PHP 8.4
  • WP_DEBUG enabled
Description

Since 6.8.10, any get_field() / get_option()-style ACF read made before WordPress creates the main query triggers a PHP notice:

PHP Notice: Function is_preview was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. (This message was added
in version 3.1.0.) in wp-includes/functions.php on line 6131

The notice fires on every such call, so production logs fill up quickly. It also breaks sites that convert notices to exceptions: with Whoops in development, the request ends in
a 500.

Cause

acf_revisions::acf_validate_post_id() (includes/revisions.php) is hooked to acf/validate_post_id, so it runs on every field read. In 6.8.10 its early bail changed:

- // bail early if no preview in URL
- if ( ! isset( $_GET['preview'] ) ) {
+ // Bail early if not a well-formed WordPress preview context.
+ if ( ! is_preview() ) {
      return $post_id;
  }

is_preview() calls _doing_it_wrong() when the global $wp_query is not set yet. WordPress only creates it in wp-settings.php after plugins_loaded. Reading options while
plugins load (settings, feature flags, service bootstrapping) is a common and legitimate pattern, and before 6.8.10 it produced no notice.

Steps to reproduce
  1. Enable WP_DEBUG and WP_DEBUG_LOG.

  2. Add to any plugin:

    add_action( 'plugins_loaded', function () {
        get_field( 'any_field', 'option' );
    } );
    
  3. Load any front-end page.

Expected

No notice, as in 6.8.9 and earlier.

Actual

The is_preview was called incorrectly notice is logged on every call.

Suggested fix

Before the main query exists, is_preview() returns false anyway, so bailing out without calling it keeps the behavior identical:

global $wp_query;

if ( ! isset( $wp_query ) || ! is_preview() ) {
    return $post_id;
}
Workaround

Right after ACF loads, we replace ACF's callback on acf/validate_post_id with a wrapper. The wrapper calls acf()->revisions->acf_validate_post_id() only when
$GLOBALS['wp_query'] is set.

Dominant language
PHP
Stars
947
Forks
198
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AdvancedCustomFields/acf

All issues in AdvancedCustomFields/acf

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.