• Hi I am trying to create several new content types in one fell swoop. However, it seems I am having some issues when I try to create more than one custom post type.

    Below I have created an array with shared arguments for register_post_type()… I then have the arguments unique to each post type such as ‘label’, ‘singular’ and ‘query_var’, then call the register_post_type() with the appropriate content type name…

    When I have both at the same time, they show up but the Admin page says ‘No Posts to display’ instead of a table with the posts, even though it says there are posts. When I comment out the second register_post_type() function however the single post type will display that table… Am I doing something wrong? How can I declare multiple, similar content types as easily as possible?

    `add_action(“init”, “price_Init”);
    function price_Init()
    {
    $arguments= array();
    $arguments[‘public’] = true;
    $arguments[‘show_ui’] = true;
    $arguments[‘_builtin’] = false;
    $arguments[‘_edit_link’] = ‘post.php?post=%d’;
    $arguments[‘capability_type’] = ‘post’;
    $arguments[‘hierarchical’] = false;
    $arguments[‘supports’] = array(‘title’,’author’, ‘excerpt’, ‘editor’);

    $arguments[‘rewrite’] = array(“slug” => ‘alert’);
    $arguments[‘query_var’] = ‘alert’;
    $arguments[‘label’] = __(‘Alerts’);
    $arguments[‘singular_label’] = __(‘Alert’);
    register_post_type(‘alerts’, $arguments);

    $arguments[‘rewrite’] = array(“slug” => ‘order’);
    $arguments[‘query_var’] = ‘order’;
    $arguments[‘label’] = __(‘Orders’);
    $arguments[‘singular_label’] = __(‘Order’);
    //register_post_type(‘orders’, $arguments);

    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • Using your code:

    add_action("init", "price_Init");
    function price_Init()
    {
    $arguments= array();
    $arguments['public'] = true;
    $arguments['show_ui'] = true;
    $arguments['_builtin'] = false;
    $arguments['_edit_link'] = 'post.php?post=%d';
    $arguments['capability_type'] = 'post';
    $arguments['hierarchical'] = false;
    $arguments['supports'] = array('title','author', 'excerpt', 'editor');
    
    $arguments['rewrite'] = array("slug" => 'alert');
    $arguments['query_var'] = 'alert';
    $arguments['label'] = __('Alerts');
    $arguments['singular_label'] = __('Alert');
    register_post_type('alerts', $arguments);
    
    $arguments['rewrite'] = array("slug" => 'order');
    $arguments['query_var'] = 'order';
    $arguments['label'] = __('Orders');
    $arguments['singular_label'] = __('Order');
    register_post_type('orders', $arguments);
    }

    I see two sections in the admin menu, one for “Alerts” and one for “Orders”.

    Now you just need to do Add New for each of those to create different Alerts and Orders.

    Also review examples at Function_Reference/register_post_type

    Thread Starter jessedrelick

    (@jessedrelick)

    Yes they displayed correctly in the admin menu… However, after adding new ‘Alerts’ or ‘Orders’, if I click ‘Alerts’ or ‘Orders’ it brings me to the page where it usually displays all posts/pages in list view… However, when I have both the list view does not display and it says ‘No posts found’ and yet says All (1) | Published (1) right below the Title of the page…

    I know there are posts there, and they will display in list view when there is only one content type active, but as soon as there are multiple ‘No posts found’ comes up even though there are some.

    Thread Starter jessedrelick

    (@jessedrelick)

    Well interestingly enough it seems it is only the ‘orders’ content type that is tripping things up… i have 3 other content types that work fine with each other, but as soon as i add the orders content type non will display posts, and orders by itself won’t either… strange…

    Thread Starter jessedrelick

    (@jessedrelick)

    Well it seems that the ‘orders’ content type is what is causing the problem, because when I changed all of the parameters for ‘orders’ to ‘test’ it seemed to work fine… kind of strange but i am assuming somewhere in the core ‘orders’ is being used… aside from that i have no clue why it wouldn’t work!!! any feedback would be helpful…

    This works okay for me:

    add_action("init", "price_Init");
    function price_Init()
    {
      $labels = array(
        'name' => _x('Orders', 'post type general name'),
        'singular_name' => _x('Order', 'post type singular name'),
        'add_new' => _x('Add New', 'order'),
        'add_new_item' => __('Add New Order'),
        'edit_item' => __('Edit Order'),
        'new_item' => __('New Order'),
        'view_item' => __('View Order'),
        'search_items' => __('Search Orders'),
        'not_found' =>  __('No orders found'),
        'not_found_in_trash' => __('No orders found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','author', 'excerpt', 'editor')
      );
      register_post_type('orders',$args);
    
        $labels = array(
        'name' => _x('Alerts', 'post type general name'),
        'singular_name' => _x('Alert', 'post type singular name'),
        'add_new' => _x('Add New', 'alert'),
        'add_new_item' => __('Add New Alert'),
        'edit_item' => __('Edit Alert'),
        'new_item' => __('New Alert'),
        'view_item' => __('View Alert'),
        'search_items' => __('Search Alerts'),
        'not_found' =>  __('No alerts found'),
        'not_found_in_trash' => __('No alerts found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','author', 'excerpt', 'editor')
      );
      register_post_type('alerts',$args);
    
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Content Types’ is closed to new replies.