I need to add random description to the game. Game description must contain a game title like this
'1' => 'some text1 (game_title) some text'
After that, new description send to database. Here is my code.
$game_descr = array('1' => 'some text1 (post_title) some text' ,
'2' => 'some text2 (post_title) some text' ,
'3' => 'some text3 (post_title) some text' ,
'4' => 'some text4 (post_title) some text' ,
'5' => 'some text5 (post_title) some text' ,
'6' => 'some text6 (post_title) some text' ,
'7' => 'some text7 (post_title) some text' ,
'8' => 'some text8 (post_title) some text' ,
'9' => 'some text9 (post_title) some text' ,
);
$newtable = $wpdb->get_results("SELECT ID, post_title, post_content FROM wp_posts WHERE post_status = 'publish'");
foreach ($newtable as $gametable) {
foreach ($game_descr as $i => $value) {
$rand_value = rand(1,9);
}
echo '<div class="game_descr"><textarea name="game_descr">'.$game_descr[$rand_value].'<br />'.$gametable->post_content.'</textarea></div>';
}
I do not publis database updating code, becouse it work) So, how to add game title to the description?
post_titlein your$game_descrand thepost_titlein your query? Is the value from the query supposed to replace the value in the array?foreach()loop -foreach ($game_descr as $i => $value)- inside theforeach()loop from your query? You are basically overwriting$rand_value8 times, and only getting the last value. Just do the$rand_value = rand(1,9);without theforeach()that is wrapping it.