Forums

[resolved] Registering multiple custom post types (4 posts)

  1. yolise
    Member
    Posted 3 months ago #

    I searched but it seems that others having this issue figure it out for themselves before anyone has a chance to reply and the solution never gets posted.

    Everytime I try to register a second post type, it breaks my function file. I assume this is because your can't just duplicate the add_action init or the function name, but not being all that when it comes to php, I'm not sure which can and can't be reused.

    Can someone explain how to register more than one custom post type?

  2. kionae
    Member
    Posted 3 months ago #

    I do it like this:

    function my_create_post_types() {
    	register_post_type( 'my_post_type', $args);
    	register_post_type( 'my_other_post_type', $args);
    }
    add_action( 'init', 'my_create_post_types' );
  3. yolise
    Member
    Posted 3 months ago #

    Ah, that's the ticket! Thanks - I'm sure this will all make sense to me one day.

    I notice that your add_action init comes after the function. Mine's before and it still seems to work. Does it matter?

  4. kionae
    Member
    Posted 3 months ago #

    The order doesn't matter. I just do it that way because it make more sense to my brain. ;)

Reply

You must log in to post.

About this Topic