Last active
April 15, 2016 10:13
-
-
Save MatRouault/55c0307d7ddf0d7bcb4a6e48a75751ad to your computer and use it in GitHub Desktop.
Add Jobs Custom Post Type with taxonomy. Custom Fields built with Beans Framework APi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Jobs CPT | |
Plugin URI: http://yourwebsite.com/ | |
Description: Add Jobs CPT with taxonomy. Custom fields built with Beans Framework. | |
Version: 1.0 | |
Author: You. | |
Author URI: http://yoururl.com/ | |
License: GPLv2 | |
*/ | |
// Exit if accessed directly | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
// Register Jobs Custom Post Type | |
function yourthemeprefix_create_cpt_jobs() { | |
$labels = array( | |
'name' => _x( 'Jobs', 'Post Type General Name', 'sps' ), | |
'singular_name' => _x( 'Job', 'Post Type Singular Name', 'sps' ), | |
'menu_name' => __( 'Jobs', 'sps' ), | |
'name_admin_bar' => __( 'Jobs', 'sps' ), | |
'archives' => __( 'Jobs Archives', 'sps' ), | |
'parent_item_colon' => __( 'Parent Job:', 'sps' ), | |
'all_items' => __( 'Toutes les offres', 'sps' ), | |
'add_new_item' => __( 'Ajouter une nouvelle offre', 'sps' ), | |
'add_new' => __( 'Ajouter une offre', 'sps' ), | |
'new_item' => __( 'Nouvelle offre', 'sps' ), | |
'edit_item' => __( 'Editer l\'offre', 'sps' ), | |
'update_item' => __( 'Mettre à jour l\'offre', 'sps' ), | |
'view_item' => __( 'Voir l\'offre', 'sps' ), | |
'search_items' => __( 'Chercher une offre', 'sps' ), | |
'not_found' => __( 'Pas de résultat', 'sps' ), | |
'not_found_in_trash' => __( 'Pas de résultat dans la corbeille', 'sps' ), | |
'featured_image' => __( 'Image à la une', 'sps' ), | |
'set_featured_image' => __( 'Choisir l\'image en une', 'sps' ), | |
'remove_featured_image' => __( 'Supprimer l\'image en une', 'sps' ), | |
'use_featured_image' => __( 'Utiliser comme image en une', 'sps' ), | |
'insert_into_item' => __( 'Insérer dans cette ofre', 'sps' ), | |
'uploaded_to_this_item' => __( 'Télécharger dans cette offre', 'sps' ), | |
'items_list' => __( 'Liste des offres de jobs', 'sps' ), | |
'items_list_navigation' => __( 'Navigation de la liste', 'sps' ), | |
'filter_items_list' => __( 'Filtrer dans la liste des offres', 'sps' ), | |
); | |
$args = array( | |
'label' => __( 'Job', 'sps' ), | |
'description' => __( 'CPT to create a job dashboard', 'sps' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'custom-fields' ), | |
//'taxonomies' => array( 'category', 'post_tag' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-businessman', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'post', | |
); | |
register_post_type( 'jobs', $args ); | |
} | |
add_action( 'init', 'yourthemeprefix_create_cpt_jobs', 0 ); | |
// Register Custom Taxonomy for Jobs CPT | |
function yourthemeprefix_create_tax_jobs() { | |
$labels = array( | |
'name' => _x( 'Types de poste', 'Taxonomy General Name', 'sps' ), | |
'singular_name' => _x( 'Type de poste', 'Taxonomy Singular Name', 'sps' ), | |
'menu_name' => __( 'Types de poste', 'sps' ), | |
'all_items' => __( 'Tous les types de postes', 'sps' ), | |
'parent_item' => __( 'Parent Item', 'sps' ), | |
'parent_item_colon' => __( 'Parent Item:', 'sps' ), | |
'new_item_name' => __( 'Nouveau type de poste', 'sps' ), | |
'add_new_item' => __( 'Ajouter un nouveau type', 'sps' ), | |
'edit_item' => __( 'Editer le type de poste', 'sps' ), | |
'update_item' => __( 'Mettre à jour le type de poste', 'sps' ), | |
'view_item' => __( 'Voir le type de poste', 'sps' ), | |
'separate_items_with_commas' => __( 'Séparer les types par des virgules', 'sps' ), | |
'add_or_remove_items' => __( 'Ajouter ou supprimer des types de poste', 'sps' ), | |
'choose_from_most_used' => __( 'Choisir parmi les plus utilisés', 'sps' ), | |
'popular_items' => __( 'Types de poste les plus populaires', 'sps' ), | |
'search_items' => __( 'Chercher dans les types de poste', 'sps' ), | |
'not_found' => __( 'Pas de résultat', 'sps' ), | |
'no_terms' => __( 'Pas de types de poste', 'sps' ), | |
'items_list' => __( 'Liste des types de poste', 'sps' ), | |
'items_list_navigation' => __( 'Navigation de la liste', 'sps' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'job_type', array( 'jobs' ), $args ); | |
} | |
add_action( 'init', 'yourthemeprefix_create_tax_jobs', 0 ); | |
//* Add Custom Fields for Jobs CPT with Beans | |
add_action( 'admin_init', 'yourthemeprefix_add_jobs_custom_fields' ); | |
function yourthemeprefix_add_jobs_custom_fields() { | |
$fields = array( | |
array( | |
'id' => 'jobs_field_id_1', | |
'label' => 'Field label 1', | |
'description' => 'Field description', | |
'type' => 'text', | |
'default' => '' | |
), | |
array( | |
'id' => 'jobs_field_id_2', | |
'label' => 'Field label 2', | |
'description' => 'Field description', | |
'type' => 'textarea', | |
'default' => '' | |
), | |
array( | |
'id' => 'jobs_field_id_3', | |
'label' => 'Field label 3', | |
'description' => 'Field description', | |
'type' => 'checkbox', | |
'default' => bool | |
), | |
array( | |
'id' => 'jobs_field_id_4', | |
'label' => 'Field label 4', | |
'description' => 'Field description', | |
'type' => 'radio', | |
'default' => 'value_1', | |
'options' => array( | |
'value_1' => 'Text 1', | |
'value_2' => 'Text 2', | |
'value_3' => 'Text 3', | |
'value_4' => 'Text 4', | |
) | |
), | |
); | |
beans_register_post_meta( $fields, array( 'jobs' ), 'section_id', array( 'title' => 'Informations' ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment