• Hey there,

    I’m working with a tricky situation where the child sites might have MORE data in an ACF repeater field than the parent site broadcasting information down. In doing so, we’re trying to preserve any data on the child site on broadcast, but allow the parent fields to broadcast down. To do this, we’ve setup a hidden ACF field that holds a unique ID that is only set on the parent. If the child doesn’t have this ID, we know it is unique to the child and should be preserved.

    The issue is, I’m hooking into threewp_broadcast_broadcasting_modify_post to modify the post_custom_fields within the broadcast data ($action->broadcasting_data->post_custom_fields).

    Doing the following to modify a known field value works:
    $action->broadcasting_data->post_custom_fields[‘topic_0_topic_title’] = ‘TEST’;

    The child gets the title ‘TEST’ and the parent still has the original title.

    However, if I loop through the child fields and add the added fields to the post_custom_fields array (along with their ACF field key ‘_topic_4_topic_text’ = field_5452b42467f6a), the child doesn’t seem to keep the data.

    I’ve confirmed the $action->broadcasting_data->post_custom_fields contains all of the fields as expected.

    Is there something else that needs to be updated to make this work? Any advice/help would be greatly appreciated! If you need more details or clarification, please let me know.

    Broadcast Version: 16
    Blog Groups Version: 16
    Premium Pack Version: 16

    Much appreciated!
    Justin

    https://www.ads-software.com/plugins/threewp-broadcast/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author edward_plainview

    (@edward_plainview)

    Could it be that you’re modifying the post too fast?

    You’re using broadcasting_modify_post. After that the custom fields are handled.

    How about using broadcasting_before_restore_current_blog and inserting the metadata there?

    Thread Starter Justin Korn

    (@themonko)

    Hey Edward,

    Nope, broadcasting_before_restore_current_blog is called AFTER the post is modified, so at that point, the child post already has the new fields and the ones I need to keep have already been overwritten.

    Any other thoughts?

    Plugin Author edward_plainview

    (@edward_plainview)

    How about both ways: during modify_post you save the post’s current meta.

    It is then completely overwritten efter modify_post, as normal.

    Then you using before_restore to put your original + extra meta there. You could, instead of using modify_post, use after_switch_to_blog.

    Not the most effective way of doing things, but better than nothing.

    after_switch and before_restore is a very popular hook pair I usually use in the plugins.

    Thread Starter Justin Korn

    (@themonko)

    Thanks for the quick replies, Edward. Unfortunately, something is still up…

    I did as you suggested. I saved child fields to be added back in during the modify_post action. Then, during before_restore_current_blog, I loop through and update the fields on the post with the fields I saved using update_field (https://www.advancedcustomfields.com/resources/update_field/)

    Two things happened:
    1) The child post didn’t get the updated fields from the parent (the ones that should be updated)
    2) The child now has 2 of the child fields I saved.

    So, it is clear for whatever reason, the child isn’t being updated at all in this scenario.

    Thoughts?

    Plugin Author edward_plainview

    (@edward_plainview)

    Without being 100% clear on what you want to do, here is what I’d do:

    – after_switch, I store the child post’s meta
    – I merge together the current meta with the parent meta
    – before_restore, I delete all of the meta and insert the merged meta

    Forget about modify_post, that’s just used for modifying the post itself, not the meta.

    Thread Starter Justin Korn

    (@themonko)

    Hey Edward,

    The main issue and what I want to do is preserve fields within an ACF repeater field that have been added to a child (being broadcasted to) that do not exist on the parent (the broadcaster).

    Let’s say the parent has topic_0_topic_name, topic_0_topic_details, topic_1_topic_name, topic_1_topic_details.

    And the child has topic_0_topic_name, topic_0_topic_details, topic_1_topic_name, topic_1_topic_details, topic_2_topic_name, topic_2_topic_details.

    When the broadcast happens, I want to make sure the child doesn’t lose topic_2_topic_name, topic_2_topic_details since those don’t exist on the parent.

    While I could potentially save all of the meta and re-add it as you suggest, this would cause a ton of more calls to the server and seems redundant to part of what the plugin is supposed to be doing.

    Ideally, there should be a way to only have to re-add the differences. And, as it seems, there is no way to do that. During modify, the changes don’t stick. During before_restore, it is as if the changes never happened (any of them). It seems as if something is happening between modify and before_restore that checks the data and if they don’t match nothing happens or something along those lines causing things not to work properly.

    I hope that helps clarify what I’m trying to accomplish and why it isn’t working as is.

    I look forward to any further thoughts.

    Thanks,
    Justin

    Thread Starter Justin Korn

    (@themonko)

    Hey Edward,

    I’ve done a few more test to see if I could figure out a work around:

    1) I tried hooking into post_updated to see where/when it is triggered and it seems it is triggered after after_switch_to_blog and before modify_post. Which is interesting that the child post would be ‘updated’ BEFORE the modify_post action. In any case, I tried capturing my data in after_switch_to_blog and then updating the post with the new data in post_updated but it seems your plugin overwrites that data again afterwards. So that didn’t work.

    2) I tried collecting all data in after_switch_to_blog (at this point, collecting the data I want to save isn’t the issue) and then waiting until your plugin hooks into broadcasting_finished. I’d only assume, at that point, everything is done. Nope, If I loop through the saved data and try to update the appropriate post in the appropriate blog (via switch_to_blog), the same thing happens as before where the child post (being broadcast too) doesn’t get the broadcasted data at all and the fields I tried to save and add are then doubled.

    So, I’m convinced, something in your plugin is happening after the fact that isn’t documented that isn’t allowing me to update the child post and allow the plugin to function as expected.

    Any further guidance would be greatly appreciated. I’m happy to share code, screen shares, etc with you however you’d like to try to get to the bottom of this.

    Thanks again.

    Plugin Author edward_plainview

    (@edward_plainview)

    I think it would help if you sent me your code so I can have a look.

    [email protected]

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding Custom Fields to the Broadcast’ is closed to new replies.