Identificarse | Registrarse | FAQ
Anonymous

HTML shortcode problem

+ Publicar una respuesta

1 mensaje Página 1 de 1


HTML shortcode problem

por amyong » Sab Mar 05, 2016 1:09 pm

I have created a site with acool theme and now I want to create a wordpress shortcode like [chapter]text[/chapter]. My code is below:
function chapters( $atts, $content ) {
$postid = get_post($my_id);

$result_chaptertitle = mysql_query("SELECT * FROM ltd_chapters_titles WHERE chaptertitle='$content' AND postid='$postid'");
$num_rows_chaptertitle = mysql_num_rows($result_chaptertitle);

$result_chaptercount = mysql_query("SELECT * FROM ltd_chapters WHERE postid='$postid'");
$num_rows_chaptercount = mysql_num_rows($result_chaptercount);

if ($num_rows_chaptertitle == 0) {
mysql_query("INSERT INTO ltd_chapters_titles (postid, chaptertitle) VALUES ('$postid','$content')");
}

if ($num_rows_chaptercount == 0) {
mysql_query("INSERT INTO ltd_chapters (postid, chapter) VALUES ('$postid', 1)");
} else {
mysql_query("UPDATE ltd_chapters SET chapter=chapter+1 WHERE postid='$postid'");
}

$chaptercount = mysql_query("SELECT chapter FROM table WHERE postid='$postid'");

mysql_query("UPDATE ltd_chapters SET count='$chaptercount' WHERE postid='$postid' AND chaptertitle='$content'");

return '<div id="chapter'.$chaptercount.'"><h3>'.$content.'</h3></div>';

}
add_shortcode('chapter', 'chapters');

But when I apply this codes in a post, the entire content of the post doesn't show up on the page.What I have been doing wrong? I'm pretty new to PHP.
Avatar de Usuario

amyong

  • Mensajes: 1
  • Registrado: Sab Mar 05, 2016 12:38 pm


+ Publicar una respuesta

Página 1 de 1