Search code examples
phpwordpresscontent-typepodscms

How to update data with the help of PODSCMS?


Hello All,

I know how to fetch record with the help of podscms, But I would like to update the record fetched by podscms. like

$somePod = pods('somepod')->update($my_array);

Anybody have some suggestion,


Solution

  • This is available in pods()->save() - http://pods.io/docs/save/

    <?php
    // Get the book item with an ID of 5
    $pod = pods( 'book', 5 );
    
    // Set the author (a user relationship field)
    // to a user with an ID of 2
    $pod->save( 'author', 2 );
    
    // Set a group of fields to specific values
    $data = array(
        'name' => 'New book name',
        'author' => 2,
        'description' => 'Awesome book, read worthy!'
    );
    
    // Save the data as set above
    $pod->save( $data );
    
    // Or the shorthand
    $id = pods( 'yourpod', $id )->save( $data );
    

    Also available is add() - http://pods.io/docs/add/