I'm creating a custom options page on my site.
One of the options is controlling a box on the homepage and i'm trying to set the link for the item to any page on the site via a select
menu.
as of now I can list all the pages including my custom post types - what I'm trying to do is also have the custom post type archive page as a link as well as some sort of ordering in the list.
So for example the select hierarchy should be something like this: Work - (Custom Post Type Archive) Matchbox - (Custom Post Type Page) Page - (Regular Page)
My current code:
$sitePages= get_posts(array('post_type'=>array('page', 'work', 'people'), 'posts_per_page'=>-1, 'post_status'=>'publish', 'depth'=> 0));
$wp_cats = array();
foreach ($sitePages as $page_list ) {
$wp_cats[$page_list->ID] = $page_list->post_title;
}
array_unshift($wp_cats, " ");
and then a foreach on $wp_cats
calls it back.
any help would be greatly appreciated!
*****UPDATE*** Based on Sven's answer ∨∨
I used the following code to output everything.
<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<option value="">Choose A Page</option>
<?php
$post_types = array( 'page', 'work', 'people' );
$wp_cats = array();
foreach ( $post_types as $post_type ) {
$pages = get_pages( array( 'post_type'=>$post_type, 'posts_per_page'=>-1, 'post_status'=>'publish', 'depth'=> 0 ) );
$obj = get_post_type_object( $post_type );
// output custom post type archive with link
if ( $post_type !== 'page' ){
echo '<option value="' . get_post_type_archive_link( $post_type ) .'"';
if (get_option( $value['id'] ) == get_post_type_archive_link( $post_type )) { echo 'selected="selected"'; }
echo '>'. $obj->labels->singular_name . '</option>';
}
foreach ( $pages as $page ) {
$wp_cats[$page->ID] = $page->post_title;
// output posts with link
echo '<option value="' . get_permalink($page->ID).'" ';
if (get_option( $value['id'] ) == get_permalink($page->ID)) { echo 'selected="selected"'; }
echo '> '. $page->post_title .'</option>';
}
}
?>
</select>