The error log result appears to check out. Parent and child post IDs given by the function are correct. For whatever reason, though, no value is being saved to the field in question.
What I want to achieve, in the end, seems relatively straightforward. When the post relationship is effected, I want a record of the parent-post ID held in a field I’ve provided for the purpose in the child post. (This is to facilitate some multi-filter front-end querying I’m doing with the post types elsewhere.)
Your code looks rather more complicated than it needs to be.
I just tried something very similar on my local test site, where I have a project-task one-to-many relationship, and with the following code I stored the parent ID on the child post with the following code:
Thank you for the quick reply, Nigel. Your recommendation here returns me to my starting point. When the hook didn’t take, with first attempts, in the straightforward way it seemed it should work, I went looking for further info and found the 2020 ticket with your two-step maneuver. I have explored and tried a number of things since that initial test, though, and it probably is a good step at this point to do another round with a simple implementation, on chance that previous attempts were missing something. Will do that and follow up later today.
My apologies. Circumstances with the project have prevented keeping this problem immediately to fore. I’ve handled it with a temporary workaround for the moment, but would like to keep the ticket open until I can return to it. It looks like I’m nearly clear to do that — within next day, I think.
I came back to this issue at some point after being overtaken with a number of others in course of work on the project, but without remembering the ticket here. The working version I ended up with, I’ll just note, is as simple as Nigel indicates, except that I see that I’ve included all five parameters in the parens. Not necessary, I recognize, and I no longer recall how this came into my rewrite. The other curious thing I notice, though, is that I’ve got this as a filter instead of an action, which seems contrary to the documentation. I don’t know now how I arrived at this. It might have been accidental. But the function seems to work either way.