无变量$my_id
在线【3】,$postid
将默认为查询中当前的post对象,很可能无法使用对象$postid
作为字符串,通常是致命错误,我希望代码能说明问题,但我强烈建议您提高对WordPress和;PHP-查看手册,阅读博客,如果合适的话可以买一本书!
function chapters( $atts, $content )
{
// We need access to some variables outside the function, so globalise them.
global $wpdb, $post;
$chapter_title = $wpdb->get_row(
$wpdb->prepare(
\'SELECT * FROM ltd_chapters_titles WHERE chaptertitle = %s AND postid= %d\',
$content, $post->ID
)
);
if ( ! $chapter_title ) {
// Make use of all the handy methods $wpdb has to offer!
$wpdb->insert( \'ltd_chapters_titles\',
array( \'chaptertitle\' => $content, \'postid\' => $post->ID ),
array( \'%s\', \'%d\' )
);
}
// For sanity to inject straight into string rather than prepare()
$post_id = absint( $post->ID );
if ( $wpdb->get_var( "SELECT postid FROM ltd_chapters WHERE postid = $post_id" ) ) {
$wpdb->query( "UPDATE ltd_chapters SET chapter=chapter+1 WHERE postid = $postid" );
} else {
$wpdb->insert( \'ltd_chapters\',
array( \'chapter\' => 1, \'postid\' => $post->ID ),
array( \'%d\', \'%d\' )
);
}
$chapter = $wpdb->get_var( "SELECT chapter FROM ltd_chapters WHERE postid = $post_id" );
$wpdb->update( \'ltd_chapters\',
array( \'count\', $count ),
array( \'postid\' => $post_id ),
\'%s\',
\'%d\'
);
return sprintf( \'<div id="chapter%d"<h3>%s</h3></div>\', $chapter, $content );
}
要有信心,不要放弃!