有时在我的错误日志中,我会出现以下错误:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to
use near \'\' at line 1
SELECT *
FROM c_posts
WHERE id = ,
do_action(\'wp_ajax_inline-save\'),
call_user_func_array,
wp_ajax_inline_save,
edit_post,
wp_update_post,
wp_insert_post,
wp_transition_post_status,
do_action(\'transition_post_status\'),
call_user_func_array,
apt_check_required_transition,
apt_publish_post,
W3_Db->query
如何修复此问题?
我认为这个插件有错误。这是一段代码:
/**
* Function to check whether scheduled post is being published. If so, apt_publish_post should be called.
*
* @param $new_status
* @param $old_status
* @param $post
* @return void
*/
function apt_check_required_transition($new_status=\'\', $old_status=\'\', $post=\'\') {
global $post_ID; // Using the post id from global reference since it is not available in $post object. Strange!
if (\'publish\' == $new_status) {
apt_publish_post($post_ID);
}
}
/**
* Function to save first image in post as post thumbmail.
*/
function apt_publish_post($post_id)
{
global $wpdb;
// First check whether Post Thumbnail is already set for this post.
if (get_post_meta($post_id, \'_thumbnail_id\', true) || get_post_meta($post_id, \'skip_post_thumb\', true)) {
return;
}
$post = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE id = $post_id");
// Initialize variable used to store list of matched images as per provided regular expression
$matches = array();
// Get all images from post\'s body
preg_match_all(\'/<\\s*img [^\\>]*src\\s*=\\s*[\\""\\\']?([^\\""\\\'>]*)/i\', $post[0]->post_content, $matches);
if (count($matches)) {
foreach ($matches[0] as $key => $image) {
/**
* If the image is from wordpress\'s own media gallery, then it appends the thumbmail id to a css class.
* Look for this id in the IMG tag.
*/
preg_match(\'/wp-image-([\\d]*)/i\', $image, $thumb_id);
$thumb_id = $thumb_id[1];
// If thumb id is not found, try to look for the image in DB. Thanks to "Erwin Vrolijk" for providing this code.
if (!$thumb_id) {
$image = substr($image, strpos($image, \'"\')+1);
$result = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE guid = \'".$image."\'");
$thumb_id = $result[0]->ID;
}
// Ok. Still no id found. Some other way used to insert the image in post. Now we must fetch the image from URL and do the needful.
if (!$thumb_id) {
$thumb_id = apt_generate_post_thumb($matches, $key, $post[0]->post_content, $post_id);
}
// If we succeed in generating thumg, let\'s update post meta
if ($thumb_id) {
update_post_meta( $post_id, \'_thumbnail_id\', $thumb_id );
break;
}
}
}
}// end apt_publish_post()