Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Wordpress Custom Post Types within WP Admin Menus

I want to create three top level sections within the wp admin area, which then list a group of wordpress custom post types. For eg.

Things to do: (Main Group) - Events (custom post type) - Attractions (custom post type) - Shopping (custom post type) - etc

Accommodation: (Another Main Group) - Hotel (custom post type) - Bed and Breakfasts (custom post type) - etc

I would rather do these and individual custom post types than using a custom taxonomy for better organisation and control.

Also each custom post type will more than likely has further of its own taxonomies applied - eg events might have a taxonomy of outdoors, indoors etc.

I know how to create individual post types, but Im not sure of how to group them in a top level hierarchy.

like image 656
Aaron Avatar asked Jul 01 '26 23:07

Aaron


1 Answers

Solution is:

  1. Accommodation / Things to do will be template pages

  2. These templates within the admin section will have an option to list the desired post types according to a) post types and b) optionally, further taxonomies

  3. On the front end template, use a code similar to the one below to collect the right data


global $post;
$serialised_post_types = get_post_meta($post->ID,'post_types_to_list',true); //i.e. a serialised array('hotel','bnb');
$serialised_post_types = unserialize($serialised_post_types);
$args = array('post_type' => $serialised_post_types); //basic args

$res = new WP_Query($args);
like image 179
Mwayi Avatar answered Jul 05 '26 15:07

Mwayi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!