• Resolved jjci

    (@jjci)


    I am using the pods_api_pre_save_pod_item_(mypod) filter to make some automated updates to a couple of fields in a PODS CPT (tgz_location_bridge). However, I cannot retrieve the ID of the item being saved.

    The filter triggers properly and the fields are updated. However, the field values are incorrect because they are derived from information that is related to the pod entry. Without the pod entry ID, I can’t retrieve the pod item and then retrieve the related information that I require.

    I have also tried using the pods_api_post_save_pod_item(mypod) because it has a parameter for ‘$id’. However, the documentation does not clarify how that parameter can or must be used. When I used the action, I received only a zero-value for the ‘$id’ parameter, which would indicate that it is not being auto-populated by the action.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @jjci

    The first param is an array of various data related to the update.
    In here you’ll find the key params which in turn contains id.

    Alternatively you can use the 3rd parameter passed to this hook which is the ID.
    Keep in mind that you do need to define the number of parameters to pass when adding your hook with add_filter.

    Cheers, Jory

    Thread Starter jjci

    (@jjci)

    Just to clarify, the number of parameters was already set correctly (i.e. 3).

    Based on my earlier tests, the ‘$id’ value is coming in as ‘0’.

    Further, I tried to retrieve the id value from the $pieces array using keys ‘post_id’, ‘post_ID’, ‘id’ and ‘ID’. However, none of those keys returned anything.
    Rather than guessing, is there any documentation which would describe all of the available key values (e.g. “post_title”)? Or, would this list simply be the basic post elements in addition to the fields that are specific to my CPT?

    Is there a specific configuration required in order to cause the hook to populate the third parameter (i.e. $id)?

    Plugin Author Jory Hogeveen

    (@keraweb)

    the number of parameters was already set correctly (i.e. 3).

    Both in your function and your filter?

    See more info here:
    https://github.com/pods-framework/pods/blob/main/classes/PodsAPI.php#L3655-L3673

    I’m sorry we don’t have in-depth documentation for these (more advanced) filters at the moment.
    The only documentation there is at the moment: https://docs.pods.io/code/filter-reference/pods_api_pre_save_pod_item_podname/

    Cheers, Jory

    Thread Starter jjci

    (@jjci)

    Based on what I could gather from the code, I tried to retrieve the pod entry ID from various elements of the $pieces array. However, nothing worked.

    1) Would the ID value even be available during a pre-save procedure if the pod entry was being created (as opposed to updating an existing pod entry)?

    2) Within the $pieces array, would I be more likely to find the pod entry ID in the ‘object_fields’ array, the ‘fields’ array, or the ‘params’ array?

    Plugin Author Jory Hogeveen

    (@keraweb)

    1) Would the ID value even be available during a pre-save procedure if the pod entry was being created (as opposed to updating an existing pod entry)?

    No, when creating a new entry the ID isn’t available yet.
    This would only be available when the post actually exists, which isn’t the case when creating a new post in the pre phase.

    2) Within the $pieces array, would I be more likely to find the pod entry ID in the ‘object_fields’ array, the ‘fields’ array, or the ‘params’ array?

    You should use the params var.

    • This reply was modified 4 years, 3 months ago by Jory Hogeveen.
    Thread Starter jjci

    (@jjci)

    Understood. Thanks.

    Plugin Author Jory Hogeveen

    (@keraweb)

    You’re welcome, good luck with your project and let me know when you need help!

    Cheers, Jory

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘pods_api_pre_save – cannot retrieve post ID’ is closed to new replies.