Hot answers tagged

2

Just use %s for string and %d for digit replacements. Do not forget to use the proper esc_*() functions (use full text search for esc_ in the function reference). global $wpdb; $wpdb->show_errors = true; $wpdb->suppress_errors = false; ! defined( 'DIEONDBERROR' ) and define( 'DIEONDBERROR', true ); $sql = <<<SQL SELECT ID FROM ...


2

You have a problem with your query which is you can't use GROUP BY and ORDER BY before WHERE replace FROM tablename GROUP BY submit_time ORDER BY submit_time DESC with FROM tablename This is your query $results = $wpdb->get_results( 'SELECT DATE_FORMAT(FROM_UNIXTIME(submit_time), "%b %e, %Y %l:%i %p") AS Submitted, ...


2

Going to take a wild stab, but ARRAY_A will return an associative array You are then trying to access this associative array as an object Simple change: foreach($results as $result){ echo $result->Name; } To: foreach($results as $result){ echo $result['Name']; } and the error should go away!


1

An alternative, instead of writing SQL queries by hand, is to use e.g.: $post_ids = get_posts( [ 'fields' => 'ids', 'post_type' => 'attachments', 'orderby' => 'menu_order', 'order' => 'ASC', 'post__in' => wp_parse_id_list( $input_ids ) ] ); where the handy wp_parse_id_list() core ...


1

Try adding the single quotes back around the %s: $countthem = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_cmapg WHERE lang='%s'", $lang) );



Only top voted, non community-wiki answers of a minimum length are eligible