• folowc

    (@folowc)


    Hi,

    I’m trying to create code, which adds new record to DB wp_term_relationships, but it’s not working
    My code:

    $wpdb->insert(
                        $wpdb->term_relationships,
                        array(
                            'object_id' => $id,
                            'term_taxonomy_id' => '60',
                            'term_order' => '0'
                        )
                    );

    Don’t know where is my bad… I tried probably 452 combinations of $wpdb->insert()… and not even one record was added to my DB. Can anyone help me?

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

    (@bcworkz)

    Did you declare global $wpdb; first?

    Thread Starter folowc

    (@folowc)

    yup:)

    Moderator bcworkz

    (@bcworkz)

    OK then, try specifying the numbers without quotes. The fields are all for integers. Also be sure $id is also an integer and that there is not an existing row with this ID. You can supply null here to use the auto increment value. The ID used will be in $wpdb->insert_id. And/or provide a third format argument, an array of 3 '%d'

    Be sure your code actually executes. Depending on context, echo out something or use error_log(), or anything else to prove your code executed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding new record to DB by $wpdb->insert()’ is closed to new replies.