Submenu for Pods
-
Hello,
I am looking at switching to Pods from CPTUI in hopes of speeding up the load time of my site, however one of the biggest issues I will have is the number of custom post types I will be creating.
I will need to have a separate submenu or landing page from the admin menu to list all of the custom post types. Having them all in the admin menu is simply not feasible.
Any help would be greatly appreciated.
Thanks
-
You can nest CPT made with Pods under other menu items in WP admin.
When you edit a Pod (CPT/Taxonomy/etc) please go to the “Admin UI” tab and you can add the parent menu ID to nest it.
I’m assuming it would probably be best to create a custom parent link?
And is there a way to list all of your pods custom post types on one admin page so that my writers can search through the list quickly to find what they want?
-
This reply was modified 6 years, 7 months ago by
L4SN.
I’ve set up a plugin with this code to try and list all of the pods in one spot but I got a fatal error with ‘foreach’.
Here is the code –
<?php /* Plugin Name: Pods listing page */ function l4sn_pods_admin_page() { ?> <div class="wrap"> <h1><?php echo get_admin_page_title(); ?></h1> <h2>Player List</h2> <ul> <?php $pod = get_post_type(); foreach ( $pod_types_found as $pod_type ) { printf( '<li><a href="%s">%s</a>', admin_url( 'edit.php?post_type=' . $type ), $type ); } ?> </ul> </div> <?php }I’ve set up a plugin with this code to try and list all of the pods in one spot but I got a fatal error with ‘foreach’.
That is because this code is incorrect.
$pod_types_foundis not declared yet.
You can use the WordPress functionget_post_types()for that. See WP Codex: https://codex.wordpress.org/Function_Reference/get_post_typesI’m assuming it would probably be best to create a custom parent link?
You can use any admin menu parent for that so that is up to you!
This needs to be the parent menu slug. See WP documentation: https://developer.wordpress.org/reference/functions/add_submenu_page/-
This reply was modified 6 years, 7 months ago by
Jory Hogeveen.
-
This reply was modified 6 years, 7 months ago by
Jory Hogeveen.
You can use any admin menu parent for that so that is up to you!
This needs to be the parent menu slug. See WP documentation: https://developer.wordpress.org/reference/functions/add_submenu_page/The plugin I’m setting up provides a clean link and landing page so that eliminates that issue.
That is because this code is incorrect. $pod_types_found is not declared yet.
You can use the WordPress function get_post_types() for that. See WP Codex: https://codex.wordpress.org/Function_Reference/get_post_typesThanks!
I’m slowly getting there… lol
But I appreciate the help, and I’ll probably be back with more questions.
Ok, I have it set up with a link in the admin menu (sidebar) that opens a landing page to edit post types.
<?php /* Plugin Name: Pods listing page */ function l4sn_pods_admin_page() { ?> <div class="wrap"> <h1><?php echo get_admin_page_title(); ?></h1> <h2>Player List</h2> <ul> <?php $pod = get_post_type($pod); foreach ( get_post_types() as $pod ) printf ( '<li><a href="%s">%s</a>', admin_url( 'edit.php?post_type=' . $pod ), $pod); ?> </ul> </div> <?php } function l4sn_pods_menu_setup() { add_menu_page( 'Player List', 'Player List', 'edit_published_posts', 'l4sn_pods', 'l4sn_pods_admin_page' ); } add_action( 'admin_menu', 'l4sn_pods_menu_setup' );The only problem I have here is that it is listing everything that is linkable from the nave menu instead of just the custom post types from Pods.
Any help sorting that would be greatly appreciated.
-
This reply was modified 6 years, 7 months ago by
L4SN.
$pod = get_post_type($pod);is incorrect PHP code.$podis not declared yet so cannot be passed as a variable. Besides, you can remove this line completely.get_post_types()doesn’t know what plugin created the post types since it’s a WordPress function, not Pods.
https://codex.wordpress.org/Function_Reference/get_post_types
One option is to filter on the_builtinparameter like so:get_post_types( array( '_builtin' => false ) ). Though this will return all CPT that aren’t built in with WordPress (so also CPT made by other plugins).Also, see
load_podsin our documentation: https://pods.io/docs/code/pods-api/load-pods/
You’ll also find an example on that page.Hope this helps!
Thanks, Jory
That got me straightened out!
Thanks!
Here’s the code in case anyone else would like to be able to utilize it –
<?php /* Plugin Name: Pods listing page */ function pods_admin_page() { ?> <div class="wrap"> <h1><?php echo get_admin_page_title(); ?></h1> <h2>Player List</h2> <ul> <?php $post_type = get_post_types( array( '_builtin' => false ) ); foreach ( $post_type as $post_type ) printf ( '<li><a href="%s">%s</a>', admin_url( 'edit.php?post_type=' . $post_type ), $post_type); ?> </ul> </div> <?php } function pods_menu_setup() { add_menu_page( 'Player List', 'Player List', 'edit_published_posts', 'pods', 'pods_admin_page' ); } add_action( 'admin_menu', 'pods_menu_setup' );Thanks again for the help!
You’re welcome! The best way to say thanks is to leave a 5 star review at https://wordpress.org/plugins/pods/ and (if you’re feeling especially generous) become a Friend of Pods at https://friends.pods.io/
Good luck with your project!
Cheers, Jory
-
This reply was modified 6 years, 7 months ago by
The topic ‘Submenu for Pods’ is closed to new replies.