Created
June 20, 2013 22:07
-
-
Save atticoos/5827144 to your computer and use it in GitHub Desktop.
How to make a singular post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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