user2151960
user2151960

Reputation: 185

Missing argument 2 for wpdb prepare()

Please help me with this.

I got this error:

Missing argument 2 for wpdb::prepare()

For this line:

$myrows = $wpdb->get_results($wpdb->prepare("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN ('0','1','2','3','4','5','6','7','8','9')")); 

Thank you!

Upvotes: 0

Views: 866

Answers (2)

user2439481
user2439481

Reputation:

Why are you using both functions get_results() and prepare()? Do you have idea about any of these functions?

I think this may be useful for you. Can you please try this:

$myrows = $wpdb->get_results("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN ('0','1','2','3','4','5','6','7','8','9')");

Or

$myrows = $wpdb->prepare("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN %s", "('0','1','2','3','4','5','6','7','8','9')");
$getData = $wpdb->get_var($myrows);

Upvotes: 2

Shawn Mehan
Shawn Mehan

Reputation: 4568

Well, after a quick RT*M one finds that your missing second argument pointed out by the system should be parameters supporting sprint()-like placeholders, which you don't have. So you need to look over the documentation for the method and consider whether you wish to use the substitution capabilities or use a different method that doesn't require those, e.g, query().

Parameters

  • $query (string) (Required) Query statement with sprintf()-like placeholders

  • $args (array|mixed) (Required) The array of variables to substitute into the query's placeholders if being called like http://php.net/vsprintf vsprintf(), or the first variable to substitute into the query's placeholders if being called like http://php.net/sprintf sprintf().

  • $args,... (mixed) (Required) further variables to substitute into the query's placeholders if being called like http://php.net/sprintf sprintf().

Upvotes: 0

Related Questions