Skip to content

Conversation

@faisalahammad
Copy link

@faisalahammad faisalahammad commented Jan 30, 2026

Summary

This PR fixes PHP warnings that flood the log file when saving a post with a relationship field that has the "Sync associated taxonomy with this relationship" option enabled, but no bidirectional relationship (sister_id) is configured.

Fixes #7477

The Problem

When pick_sync_taxonomy is enabled but there is no bidirectional relationship set up:

  • $related_pod is null
  • $related_field is null

The original code at line 1959-1967 had this condition:

if (
    (
        empty( $related_field )
        || empty( $related_pod )
    )
    && empty( $options[ static::$type . '_sync_taxonomy' ] )
) {
    return;
}

This means the function only returns early if BOTH conditions are true:

  1. No bidirectional relationship exists, AND
  2. No taxonomy sync is enabled

So when taxonomy sync IS enabled (but no bidirectional relationship exists), the code continues past this check and then tries to access $related_pod['type'] on line 1974, which triggers the PHP warning.

The Solution

Move the taxonomy sync logic to run first (it does not need $related_pod or $related_field), then add an early return if no bidirectional relationship exists.

Before

if (
    (
        empty( $related_field )
        || empty( $related_pod )
    )
    && empty( $options[ static::$type . '_sync_taxonomy' ] )
) {
    return;
}

// Handle the bi-directional relationship updates.

$no_conflict = true;

// Only check no conflict mode if this isn't the current pod type.
if ( $related_pod['type'] !== $pod['type'] ) {  // <-- PHP Warning here!
    $no_conflict = pods_no_conflict_check( $related_pod['type'] );
}

// ... more bidirectional code ...

// Handle syncing of taxonomy terms.
if ( ! empty( $pod['type'] ) && 'post_type' === $pod['type'] && ! empty( $options[ static::$type . '_sync_taxonomy' ] ) ) {
    // taxonomy sync code
}

if ( ! $no_conflict ) {
    pods_no_conflict_off( $related_pod['type'] );  // <-- PHP Warning here too!
}

After

// Handle syncing of taxonomy terms first (doesn't require bidirectional relationship).
if ( ! empty( $pod['type'] ) && 'post_type' === $pod['type'] && ! empty( $options[ static::$type . '_sync_taxonomy' ] ) ) {
    // taxonomy sync code - runs independently
}

// Exit early if no bidirectional relationship to handle.
if ( empty( $related_field ) || empty( $related_pod ) ) {
    return;
}

// Handle the bi-directional relationship updates.
// Now we are sure $related_pod and $related_field are not null

$no_conflict = true;

if ( $related_pod['type'] !== $pod['type'] ) {
    $no_conflict = pods_no_conflict_check( $related_pod['type'] );
}

// ... rest of bidirectional code ...

if ( ! $no_conflict ) {
    pods_no_conflict_off( $related_pod['type'] );
}

Why This Works

  1. Taxonomy sync does not need $related_pod or $related_field - it only uses $pod, $options, and $value_ids
  2. By moving it to the top, it runs first regardless of whether a bidirectional relationship exists
  3. The early return after taxonomy sync prevents the bidirectional code from executing when $related_pod is null
  4. Bidirectional relationships still work exactly as before when properly configured

Testing Done

  • Tested with Pick field related to taxonomy with "Sync taxonomy" enabled
  • No bidirectional relationship (sister_id) configured
  • Saved post with taxonomy terms selected
  • Verified: No PHP warnings in debug.log
  • Verified: Taxonomy terms sync correctly to the post
  • Also tested with bidirectional relationship enabled to make sure that still works

Files Changed

  • classes/fields/pick.php - Reordered logic in the save() method

Plugin zip

pods-fix-7477.zip

This commit adds a new 'Save Value When Hidden' option for fields with conditional logic.

Problem: When a conditional field's parent condition is set to false, child field values get reset to null (Issue pods-framework#7475).

Solution:
- Added 'conditional_logic_save_value' boolean option in Field.php
- Modified PodsAPI.php to check this option before clearing hidden field values
- When enabled, the field value is preserved even when the field is not visible

Fixes pods-framework#7475
…ork#7475)

Added 'conditional_logic_save_value' option to field configuration that
allows preserving field values when the field is hidden by conditional logic.

Changes:
- Field.php: Added new 'conditional_logic_save_value' boolean option
- PodsMeta.php: Skip adding hidden fields to save data when option is enabled

This prevents the empty default value from overwriting existing database
values when conditional logic hides a field during form submission.
…ionship

When the 'Sync associated taxonomy with this relationship' option is enabled
on a Pick field but no bidirectional relationship (sister_id) is configured,
PHP warnings were raised because the code tried to access array offsets on
null values for $related_pod and $related_field.

The fix moves taxonomy sync logic to execute first (it does not need the
bidirectional relationship data), then adds an early return if no
bidirectional relationship exists. This prevents the code from attempting
to access properties on null variables.

Fixes pods-framework#7477
@what-the-diff
Copy link

what-the-diff bot commented Jan 30, 2026

PR Summary

  • Improved Method for Storing Post Data
    The changes in PodsMeta.php have fine-tuned the way we store data from posts. Now, if a field is not submitted but a certain option (conditional_logic_save_value) is enabled, the existing values in our database will be kept safe for these hidden fields. This means more secure and consistent data handling, reducing the chance of losing necessary information.

  • Simplified Synchronization of Taxonomy
    The adjustments in pick.php have improved how we match and relate elements of taxonomy, particularly in the initial stages of the save process. The procedure for dealing with post types and connected areas has been streamlined, removing unnecessary duplications. This has not only made the code easier to understand, but it also reduced its complexity, enhancing its run-time efficiency.

  • Added New Option for Field Configuration
    A new configuration option was added in Field.php. With this conditional_logic_save_value option, it's now possible to save the value of a field even if it's hidden by certain conditional logic. This update also includes help text, making it more user-friendly and ensuring the feature can be properly utilized by all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Sync associated taxonomy with this relationship" field option causing PHP warnings

1 participant