Skip to content

Instantly share code, notes, and snippets.

@atticoos
Created June 20, 2013 22:07
Show Gist options
  • Save atticoos/5827144 to your computer and use it in GitHub Desktop.
Save atticoos/5827144 to your computer and use it in GitHub Desktop.
How to make a singular post type
add_action('admin_menu', 'hook_uniquePostTypes');
function hook_uniquePostTypes(){
global $submenu, $menu;
// post types to make singular
$postTypes = array('example1', 'example2');
foreach($submenu as $key=>$value){
$name = preg_replace('/edit.php\?post_type\=/', '', $key);
foreach($postTypes as $type){
if ($type == $name){
$uniquePost = get_posts(array('post_type' => $name));
// this i worry about upon wordpress version changes
unset($submenu[$key][5]);
if ($uniquePost){
$submenu[$key][10][0] = preg_replace('/Add/', 'Edit', $submenu[$key][10][0]);
$submenu[$key][10][2] = 'post.php?post=' . $uniquePost[0]->ID . '&action=edit';
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment