Global changes to all items in a pod

This topic is: not resolved

This topic contains 5 replies, has 2 voices, and was last updated by  cathy 1 year, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #165715

    cathy
    Member

    Is there any way of resetting a single field in all items in a pod to a set value (eg zero) or to false (for a boolean field)? ie a global change? I have a membership database that I would like to reset with the change in financial year (30 June).

    I could go into the database itself, but I would prefer to do it in pods if possible.

    #165716

    chris.pilko
    Member

    You can do this with a Pods API call.

    I have some routines like this that I use for maintenance. I have Pod pages that do not show up in my site listings. I give these pages long, random strings for page names, and then use code like this on them:

    For something like this where I am reseting a variable once per year, I would probably add a check for the proper value in a changing GET value in the URL, just to make sure I didn’t call this page by accident when going through my history.

    #165717

    cathy
    Member

    Thanks. Will give this a go tonight.

    #165718

    cathy
    Member

    It’s all fine, but it seems to give me a new record with only the changed value in it (all the other fields are either the default or empty).

    It comes down to this:
    <pre> $params = array(‘datatype’ => ‘my_pod’, ‘tbl_row_id’ => $id, ‘columns’ => array(‘my_data’ => $new_value));
    $params = pods_sanitize($params);
    $api->save_pod_item($params);
    </pre>

    How do I overwrite the value in one field and not touch the others, and not create a new record in the process?

    (OK – yes I did get sidetracked on my day job for a month)

    #165719

    chris.pilko
    Member

    Fat finger on my part. You need to specify the id to overwrite data instead of creating a new record.

    Change $id to $Record->get_field(‘id’).

    #165720

    cathy
    Member

    Worked a treat. Thanks so very much.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Wordpress Cloud Hosting