How to change what the post creation page looks like?

Is there a way (plugin, or something else) to set it where there is a drop down on the “New Post” page that allows you to choose a post type and the fields change allowing you to filter what content you are putting into a post without confusing a user by having 20 different custom fields on the “New Post” page.

Also, is there a plugin or other that can make custom fields with different value types (textarea, list, file upload, etc)?

Related posts

Leave a Reply

2 comments

  1. I understand your concern; if you get a lot of post types WordPress’ admin menu quickly grows unwieldy. What I’ve done for you is to implement something like what you asked for. It creates a post edit page metabox for the new post page with a drop down list of custom post types like this:

    WordPress Custom Post Type Selector Metabox

    And here’s what it looks like with a bunch of custom post types in the drop down mode:

    What it does is use jQuery and Javascript to modify window.location.href in the browser’s DOM upon selection using one of the following URL patterns, using the post types in my list of screenshots as an example:

    http://example.com/wp-admin/post-new.php // This is for post_type=post
    http://example.com/wp-admin/post-new.php?post_type=page 
    http://example.com/wp-admin/post-new.php?post_type=actor
    http://example.com/wp-admin/post-new.php?post_type=movie
    http://example.com/wp-admin/post-new.php?post_type=car 
    http://example.com/wp-admin/post-new.php?post_type=event
    http://example.com/wp-admin/post-new.php?post_type=performer
    

    One thing I worry about is the usability of this, however, so I wrote it to disable the drop down after the user modifies the value of any input field. That way the user can’t accidently loose everything they were working on.

    The code follows and you can place this in your theme’s functions.php file or in a .php file for a plugin that you might be writing:

    add_action('add_meta_boxes', 'add_meta_boxes_post_type_switcher',10,2);
    function add_meta_boxes_post_type_switcher($post_type,$post) {
      global $pagenow;
      if ($pagenow=='post-new.php') {
        require_once(ABSPATH . 'wp-admin/includes/template.php');
        add_meta_box('post_type_switcher','Change Post Type',
                     'post_type_switcher',$post_type,'side','high');
      }
    }
    function post_type_switcher($post,$metabox) {
      $post_types = get_post_types();
      $new_post_url = admin_url('post-new.php');
      $js =<<<JS
    <script type="text/javascript">
    jQuery(document).ready(function ($) {
      $("#post-type-switcher-selector").change(function() {
        var post_type = $(this).find(":selected").val();
        var new_post_type_url = "{$new_post_url}?post_type=" + post_type;
        if (post_type=="post" && "{$new_post_url}"!=window.location.href) {
          window.location.href = "{$new_post_url}";
        } else if (new_post_type_url!=window.location.href) {
          window.location.href = new_post_type_url;
        }
      });
      $(".wp-admin #wpbody-content :input").change(function() {
        $("#post-type-switcher-selector").attr("disabled","disabled");
      });
    });
    </script>
    JS;
      echo $js;
      echo '<select id="post-type-switcher-selector">';
      foreach ( $post_types as $post_type ) {
        $post_type_object = get_post_type_object($post_type);
        if ($post_type_object->publicly_queryable && $post_type!='attachment') {
          echo "nt<option ";
          if ( $post_type == $post->post_type ) // Make default first in list
            echo "selected='selected' ";
          echo "value='{$post_type}'>";
          echo $post_type_object->labels->singular_name;
          echo "</option>";
        }
      }
      echo '</select>';
    }
    

    So there’s the code and it should work for you. If you have any questions about specifics in the code, just ask. However I would recommend you instead consider a consolidated menu like this one instead since I think it creates a more consistent mental model for the user, but the choice is yours!