How can you group custom post types in the admin sidebar?

Is there an easy way to group custom post types on the admin sidebar menu?

The reason i ask is because i want to try to accomplish the following:

Read More

I’ve created a custom post type titled “Latest News” it’s nothing more than a block area that will have a link that links out to another website so there are only two custom fields in this post type “URL” and “Headline Text”.

However I will use this custom post type on 27 other different pages and this would not even be an issue if i could just use the same content on all of those 27 pages. Instead there needs to be custom news for each of those 27 pages.

Here’s my noob approach:

I will create 27 different custom post types that have a unique description but ALL have the exact same custom fields which i’ll have to create repeatedly as well for each of the 27 pages just so that i can link them to their specific custom post type and include that unique description within the specific page that the news will be relevant to.

I know it’s a super bloated way to do things and WordPress probably has a better way to do this that requires knowing “if else” statements within custom functions. While i’m not afraid to try that i don’t know very well how to do that but am willing to work it.

So as you can tell creating 27 custom post types just for this “Latest News” block area will make my Admin menu so long, hence the title of this question on how to group CPT’s in the admin sidebar menu, but that’s not really what i’m after.

Not to mention that if i can’t find a better way to do this i’ll end up doing the same thing for 10 other custom post types i need to make that will also go on 27 pages that are all using the same template but require unique content. That alone would make a sidebar admin menu with 297 custom post types and that’s just insane.

Someone slap me and tell me what i’m doing wrong.

Thanks.

 <?php

    $args = array(
            'post_type' => 'latest_news',
            'tax_query' => array(
                   'taxonomy' => 'news',
                   'field' => 'slug'
                   )
    );

    $the_query = new WP_Query( $args );

    ?>

    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>


      <?php the_field( 'url_latest_news' ); ?>


    <?php endwhile; else: ?>


    <?php endif; ?>

Related posts

1 comment

  1. If I understand what you are doing, and I may not, I would not do this with multiple Custom Post types, much less 27 of them.

    I would…

    1. Create a single Custom Post Type for this “Latest News” data.
    2. Create a Custom Taxonomy to sort the data. This taxonomy would have
      27 terms to correspond to, and serve instead of, the CPTs that you
      are thinking about making.
    3. Create a theme template or templates to handle the data

    To make this work, you would create a new post in your CPT and mark the appropriate term in your custom taxonomy. The template(s) you create in the theme would then display posts from the CPT according to a taxonomy argument– that is display posts based on the term chosen.

Comments are closed.