Skip to content

Conversation

@gthayer
Copy link

@gthayer gthayer commented May 2, 2025

Description of the Change

This update adds support for the UI metabox to display on editor screens for post_to_post connections which have a "one to many" relationship.

The plugin supports the ability to define a "one to many" relationship, however it also intentionally disables the metabox from displaying within the editor. I am unclear why this was disabled originally, but it seems the architecture does not easily support the feature because of how relationship keys are detected and constructed.

This PR removes these restrictions and adds a "fuzzy match" to try and better identify the post relationships.

Closes #103

How to test the Change

Create a "one to many" relationship using define_post_to_post. The $to value should be an array of post types.

Once defined, ensure:

  • The UI to be visible on all relevant post types
  • The values are update-able
  • Queries to correctly display their relevant connections work as expected

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability
Developer - Non-functional update

Credits

Props @username, @username2, ...

Checklist:

@gthayer gthayer requested review from rickalee and s3rgiosan as code owners May 2, 2025 19:08
@gthayer gthayer marked this pull request as draft May 2, 2025 19:24
@gthayer
Copy link
Author

gthayer commented May 2, 2025

Converting to a draft. While this update adds the UI, it also seems to return the wrong posts in the relationship UI.

@gthayer gthayer force-pushed the feature/multiple-posttype-ui branch from 9954c01 to 0eba30f Compare May 16, 2025 13:38
@gthayer gthayer marked this pull request as ready for review May 16, 2025 13:49
$to = implode( '.', $to );

return "{$from}_{$to}_{$name}";
return "{$from}~{$to}~{$name}";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to a more obscure delimiter to avoid confusion with underscores in post type names.

return $this->post_post_relationships[ $key ];
}

// Fuzzy match the relationship by parsing the key and looping through the relationships
Copy link
Author

@gthayer gthayer May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truthfully, I'm not in love with the fuzzy match. I think this could break down if a post type name contained the name of another post type. ex: "post" and "postcard".

The challenge here is that the relationship name needs to be able to be constructed, however when the post type is one of the "many" set, it does not have knowledge of it's siblings and the key can not be constructed properly.

@jeffpaul jeffpaul added this to the 1.8.0 milestone May 20, 2025
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.

Add support for displaying the UI when multiple "to" post types are defiend.

2 participants