Jimmylet
12/13/2018 - 2:31 PM

register_new_post_type_with_taxonomy.php

<?php
/*
 * this file is mu-plugins/gallery-post-type.php
 *
 * Plugin Name: Register Gallery Post Type
 * Plugin URI: http://knok.be/
 * Description: Register a new custom post type for create galleries
 * Version: 1.0
 * Author: Knok Design
 * Author URI: http://knok.be
*/

if ( !post_type_exists( 'gallery' ) ) {
  function register_gallery_type() {
    $label_singular = 'Galerie';
    $label_plural   = 'Galeries';
    register_post_type('gallery', [
      'label'         => 'Galeries',
      'labels'        => [
        'all_items' => 'Toutes les galeries photos en base de donnée',
        'singular_name' => 'galerie',
        'add_new_item'  => 'Ajouter un nouvel album',
        'add_new'  => 'Ajouter un nouvel album',
      ],
      'hierarchical'    => true,
      'description'   => 'Permet d’ajouter des albums de photos dans la page Medias/Photos',
      'public'        => true,
      'menu_icon'     => 'dashicons-format-gallery',
      'rewrite' => [
        'slug'       => pll__('galeries'),
        'with_front' => false,
      ],
      'supports' => ['title', 'thumbnail', 'custom-fields']
    ]);
  }
  
  function gallery_categories_init() {
    register_taxonomy(
      'gallery-taxonomies',
      'gallery',
      [
        'label' => __( 'Catégories des photos' ),
        'rewrite' => ['slug' => pll__('galeries') ],
        'hierarchical'    => true,
      ]
    );
  }
  
  add_action('init', 'register_gallery_type');
  add_action( 'init', 'gallery_categories_init' );
  
}