我对wpdb prepare和sql查询有问题。如果我直接通过wpdb->get\\u results运行查询,它工作得很好。这是:
$alabala_sql = $wpdb->prepare(
"
SELECT *
FROM $wpdb->posts p
INNER JOIN $wpdb->term_relationships tr
ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt
ON tr.term_taxonomy_id=tt.term_taxonomy_id
inner join $wpdb->terms t
on t.term_id=tt.term_id and t.slug=\'$curPageId\'
WHERE
p.post_title LIKE \'$getChar%\'
AND p.post_type = \'filmi-i-serialii\'
AND p.post_status = \'publish\';
"
);
/*Make sql query to take posts*/
$eventsPosts = $wpdb->get_results($alabala_sql);
但它不起作用。我也试过这样做:
$alabala_sql = $wpdb->prepare(
"
SELECT *
FROM $wpdb->posts p
INNER JOIN $wpdb->term_relationships tr
ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt
ON tr.term_taxonomy_id=tt.term_taxonomy_id
inner join $wpdb->terms t
on t.term_id=tt.term_id and t.slug=$s
WHERE
p.post_title LIKE $s%
AND p.post_type = \'filmi-i-serialii\'
AND p.post_status = \'publish\';
", $curPageId, $getChar
);
/*Make sql query to take posts*/
$eventsPosts = $wpdb->get_results($alabala_sql);
但还是没用。请告诉我哪里错了?两个变量都是字符串。当做