Skip to content

Fix relationship name-to-post resolution - #280

Open
sirreal wants to merge 2 commits into
masterfrom
fix-relationships-connections
Open

Fix relationship name-to-post resolution#280
sirreal wants to merge 2 commits into
masterfrom
fix-relationships-connections

Conversation

@sirreal

@sirreal sirreal commented Aug 18, 2026

Copy link
Copy Markdown
Member

Three bugs in lib/class-relationships.php broke the name→slug→post-ID resolution that builds p2p connections:

  1. names_to_slugs() never detects fully qualified names. strpos( '\\', $name ) has haystack and needle swapped, so $fully_qualified is always false and a \-prefixed call is still resolved against the current namespace first. PHP semantics say a fully qualified name resolves only globally; now it does. This deliberately changes candidate order for \-qualified calls made inside a namespace.

  2. get_ids_for_slugs() connects every matching scope. The loop says "stop searching the chain" but uses continue, so when both the namespace-scoped and the global candidate resolve to posts, both are connected — duplicate/spurious p2p connections. Now the first (most specific) match wins.

  3. An empty slug map connects items to post ID 1. When no posts of a target type were imported, the raw array-of-candidate-arrays was left in $relationships, and the connection loop's intval( array, 10 ) coerces each to 1 — connecting items to whatever post has ID 1. The candidates are now cleared so nothing reaches the connection loop. This is the TODO why might this be empty? test class-IXR.php spot.

The new tests fail on master (3 of 5; the other two pin existing correct behavior) and pass with the fix; the full suite passes.

Observed while here, left alone: the methods branches of the connection loop pass 'data' => current_time( 'mysql' ) where the functions branches pass 'date' => — looks like a typo, but changing stored p2p meta is out of scope for this fix.

Found by the multi-agent review during #262; extracted as a standalone change.

🤖 Generated with Claude Code

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.

1 participant