WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to insert data into custom meta table (4 posts)

  1. vbmark
    Member
    Posted 2 months ago #

    Hello,

    I have a custom meta table I created named carsmeta. I copied the table structure from another meta table.

    How do I insert data into this table? I tried using add_metadata

    add_metadata( 'carmeta', 1, "Ford", "Blue" );

    but that doesn't work.

    Also, what is the best way to structure/format the data for the value?

    Thanks!

  2. bcworkz
    Member
    Posted 2 months ago #

    You can't use native WP functions on custom tables, the functions have no idea on how to address them. You can use $wpdb methods though. $wpdb knows how to access the database and can use any mySQL query you care to create. You will likely use $wpdb->insert() and $wpdb->update(), though you can supply any full mySQL query to $wpdb->query(). If you do it that way, be sure to use $wpdb->prepare() first. $wpdb->query() does not return results. If you are expecting results, they will be in $wpdb->last_result

    To store several related data items as a single value, just assemble the data into an array: array( 1, 'Ford', 'Blue')

  3. vbmark
    Member
    Posted 2 months ago #

    Thank you, bcworkz! I wish I could up-vote you or something. I really appreciate it.

    Thanks!

  4. bcworkz
    Member
    Posted 2 months ago #

    Up-votes :D
    Thanks are all I need, so you are most welcome!

Reply

You must log in to post.

About this Topic