Title: How do I add a row programatically, with php?
Last modified: August 22, 2016

---

# How do I add a row programatically, with php?

 *  Resolved [partysoft](https://wordpress.org/support/users/partysoft/)
 * (@partysoft)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/)
 * How do I add a row with php?
    I need to sync some post types with some data from
   the table and I want to just call an insert or update of a certain row with PHP
 * How do I do that?
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/#post-5496867)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * Sorry, that’s not that easy. Editing tables should only be done via the “Edit”
   screen, there’s no direct PHP API.
    You would have to load the table using the
   TablePress table model, then edit the array and save it again. For details, I
   suggest to take a look at the TablePress source code, specifically at the `ajax_action_save_table`
   method in the controller-admin_ajax.php file.
 * Regards,
    Tobias
 *  Thread Starter [partysoft](https://wordpress.org/support/users/partysoft/)
 * (@partysoft)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/#post-5496908)
 * but that’s stored into the db, so it should be at least possible to just find
   the row and update it right?
 *  Thread Starter [partysoft](https://wordpress.org/support/users/partysoft/)
 * (@partysoft)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/#post-5496909)
 * well I was able to use PHP and your static methods to manipulate programtically
   the table
 * $existing_table = TablePress::$model_table->load( 1, true, true );
 * $existing_table[‘data’][]=array(0 => ‘value’,
    1 => ‘value’, 2 => ‘value’, 3 
   => “value”, 4 => “value”, 5 => “value”);
 * $existing_table[‘visibility’][‘rows’][]=1;
 * $saved = TablePress::$model_table->save( $existing_table );
 * And it works too
 * Is there any way to just load a row?
    this loads all the data from ALL the table…
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/#post-5496931)
 * Hi,
 * yes, that code looks good! Great to hear that you found that!
 * Loading just a single row (just like directly adding only a single row) is not
   possible, as TablePress doesn’t stores tables by row, but only the full table(
   a two-dimensional array) as a JSON encoded string in the `wp_posts` table.
 * Regards,
    Tobias

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How do I add a row programatically, with php?’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/how-do-i-add-a-row-programatically-with-php/#post-5496931)
 * Status: resolved