• Resolved vbmark

    (@vbmark)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    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')

    Thread Starter vbmark

    (@vbmark)

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

    Thanks!

    Moderator bcworkz

    (@bcworkz)

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to insert data into custom meta table’ is closed to new replies.