0

I'm making some customizations for a website, and I cam across this piece of code of a theme:

        $wpdb->insert(
            $table_name,
            array(
                'user_id'              => $user_id,
                'search_wp_query_args' => $search_args,
                'search_query_str'     => $search_url,
                'time'                 => current_time( 'mysql' ),
            ),
            array(
                '%d',
                '%s',
                '%s',
                '%s',
                '%s',
            )
        );

What's the reason for having one more element in the $format array than in the $data array? In the docs it implies that those should have the same number of elements, for a 1-on-1 matching... Does it account for the primary key of the table, which isn't in the $data array anyway though? Is this a bug or there is an explanation behind it?

0

1 Answer 1

2

I think you're assuming this is intentional, it's probably just a bug in the theme, what it's stating is the 5th parameter is a string, but there is no 5th parameter so it's ignored.

The most likely reason is that during development a 5th entry was removed and the author forgot to update the second array, or that they accidentally duplicated a line

1
  • Thanks for the explanation!
    – Faye D.
    Mar 19, 2023 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.