I am trying to export a list of pages from the database as an array for WordPress. This is to generate a dropdown menu of the pages from the database.
I'm a little stuck as this part of WordPress is new to me and I need a little help from any one who has had experience in creating something similar to this function.
This is my function:
function fetch_redirect_page(){
global $wpdb;
$pages = $wpdb->get_results("SELECT post_title, post_status, post_type FROM $wpdb->posts WHERE `post_status`='publish' AND `post_type`='page'");
$redirect = "";
foreach($pages as $page){
$redirect .= '"'.$page->post_title.'"';
}
$redirect = array($redirect);
return $redirect;
}
to which goes into the options section of this array.
array(
"name" => "Redirect To",
"desc" => "This will redirect the user to the page selected after the user has left a comment.",
"id" => "commentredirect",
"type" => "select",
"options" => fetch_redirect_page(),
"std" => ""
),
This is my html export results so far:
<label for="commentredirect">Redirect To</label>
<select name="commentredirect" id="commentredirect">
<option value="" about="" home="" blog="" contact="">"About""Home""Blog""Contact"</option>
</select>
<small>This will redirect the user to the page selected after the user has left a comment.</small>
which is completely wrong and will not work at all.
I need it to export like so:
<label for="commentredirect">Redirect To</label>
<select name="commentredirect" id="commentredirect">
<option value="about">About</option>
<option value="blog">Blog</option>
<option value="contact">Contact</option>
<option value="home">Home</option>
</select>
<small>This will redirect the user to the page selected after the user has left a comment.</small>
If any one can help me with this, it would very much appreciated.
Question
seb86
I am trying to export a list of pages from the database as an array for WordPress. This is to generate a dropdown menu of the pages from the database.
I'm a little stuck as this part of WordPress is new to me and I need a little help from any one who has had experience in creating something similar to this function.
This is my function:
function fetch_redirect_page(){ global $wpdb; $pages = $wpdb->get_results("SELECT post_title, post_status, post_type FROM $wpdb->posts WHERE `post_status`='publish' AND `post_type`='page'"); $redirect = ""; foreach($pages as $page){ $redirect .= '"'.$page->post_title.'"'; } $redirect = array($redirect); return $redirect; }to which goes into the options section of this array.
This is my html export results so far:
which is completely wrong and will not work at all.
I need it to export like so:
If any one can help me with this, it would very much appreciated.
Thank you.
Link to comment
Share on other sites
15 answers to this question
Recommended Posts