In order of figuring out the following issue, see https://wordpress.stackexchange.com/questions/178995/sanitize-a-working-query-string-by-using-wpdb-prepare-fails-with-mysql-db-er i ran into an rather odd behaviour. Even that my used query was correct and showing the right output.
global $wpdb;
$wpdb->show_errors();
$pageposts = $wpdb->get_results(
$wpdb->prepare(
"
SELECT skposts.*
FROM $wpdb->posts skposts,
$wpdb->postmeta skpostmeta1,
$wpdb->postmeta skpostmeta2
WHERE skposts.ID = skpostmeta1.post_id
AND skposts.ID = skpostmeta2.post_id
AND skpostmeta1.meta_key = %s
AND skpostmeta2.meta_key = %s
AND skposts.post_type = %s
AND skposts.post_status = %s
ORDER BY skpostmeta1.meta_value ASC,
skpostmeta2.meta_value ASC
",
'class_day',
'class_start',
'courses',
'publish'
)
, OBJECT
);
$wpdb->print_error();
Never the less as long as i have show_errors
and print_error
active i get an WP database error output alongside:
WordPress database error: []
SELECT skposts.* FROM hmjtZ_posts skposts, hmjtZ_postmeta skpostmeta1, hmjtZ_postmeta skpostmeta2 WHERE skposts.ID = skpostmeta1.post_id AND skposts.ID = skpostmeta2.post_id AND skpostmeta1.meta_key = 'class_day' AND skpostmeta2.meta_key = 'class_start' AND skposts.post_type = 'courses' AND skposts.post_status = 'publish' ORDER BY skpostmeta1.meta_value ASC, skpostmeta2.meta_value ASC
But why? I would have expected that an output is shown only if something goes wrong like an error or warning but this way something is shown all the time.