• NETT.PRO

    (@nettpro)


    Hi.

    I am developing a plugin. Not sure if this is the correct place to ask, if not, please point me in the correct direction.

    When developing I use the Plugin Check (PCP), which is giving me this error:
    Incorrect number of replacements passed to $wpdb->prepare(). Found 3 replacement parameters, expected 4.

    In this code:


    $query = $wpdb->prepare(
    "SELECT c.*, u.user_email,
    (SELECT meta_value FROM %1\$s WHERE user_id = u.ID AND meta_key = 'first_name') AS first_name,
    (SELECT meta_value FROM %1\$s WHERE user_id = u.ID AND meta_key = 'last_name') AS last_name
    FROM %2\$s AS c
    INNER JOIN %3\$s AS u ON c.user_id = u.ID
    $where_clause
    ORDER BY c.date_added DESC",
    $usermeta_table,
    $table_name,
    $users_table
    );

    So, I tried all kind of different solutions, could it be that the checker wants $where_clause to be represented by a placeholder?

    I have tried that but then I get this error: Incorrect number of replacements passed to $wpdb->prepare(). Found 4 replacement parameters, expected 5.
    I also tried using %s but then I get some database error..

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Apparently the checker doesn’t understand reusing the same replacement value. Use %1$s, %2$s, etc. sequential placeholders, without attempting to reuse the same value. Thus the same table name will need to be provided twice.

    You should use %i placeholders for table and column names. You will get a warning that these are only supported by versions after 6.something. If you need better reverse compatibility, %1$s can be used, but you must provide your own backtick quotes, prepare does not add quotes for sequential numbered placeholders, only the plain %s style.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.