• I am trying to run the below query and output but getting the error as seen below. I get you should add an argument but with a query that really doesnt have one what do you do?

    Just trying to get all email addresses from comments and display them.

    $myrows = $wpdb->get_results( $wpdb->prepare("SELECT DISTINCT comment_author_email FROM wp_comments" ));
    foreach ( $myrows as $myrows )
    {
    	echo $myrows->comment_author_email;
    }

    Warning: Missing argument 2 for wpdb::prepare()

    Thanks!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You don’t really need prepare() unless variables are involved. All prepare() really does is escape the variable values. FYI, prepare() must be used like sprintf() – The SQL string with %s and %d placeholders first, followed by the variables to substitute for the placeholders.

Viewing 1 replies (of 1 total)

The topic ‘Missing Argument 2 For WPDB’ is closed to new replies.