Skip to content

Instantly share code, notes, and snippets.

@GreenGeorge
Created April 22, 2012 11:03

Revisions

  1. GreenGeorge revised this gist Apr 22, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion custom-posts-helper.php
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,6 @@ function add_post_type($name, $args = array() ) {
    };

    // ***** Declare function that builds the taxonomy

    function add_taxonomy($name, $post_type, $args = array()) {

    add_action('init', function() use($name, $post_type, $args) {
  2. GreenGeorge revised this gist Apr 22, 2012. No changes.
  3. GreenGeorge created this gist Apr 22, 2012.
    51 changes: 51 additions & 0 deletions custom-posts-helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <?php

    // ***** Declare function that buids the post type
    function add_post_type($name, $args = array() ) {
    add_action('init',function() use($name, $args) {

    // make post type name capitalized
    $upper = ucwords($name);

    // make name acceptable
    $name = strtolower(str_replace(' ', '_', $name));

    // merge default args with passed args
    $args = array_merge(
    array(
    'public' => true,
    'label' => ucwords("$name" . 's'),
    'labels' => array(
    'add_new_item' => "Add New $upper" . ''),
    'supports' => array(
    'title','editor','excerpt'),
    'taxonomies' => array('category')
    ),$args);

    // build post type
    register_post_type($name, $args );
    });
    };

    // ***** Declare function that builds the taxonomy

    function add_taxonomy($name, $post_type, $args = array()) {

    add_action('init', function() use($name, $post_type, $args) {

    // make taxonomy name capitalized
    $upper = ucwords($name);
    $plural = ucwords("$name" . 's');

    // make name acceptable
    $name = strtolower(str_replace(' ', '_', $name));

    // merge default args with passed args
    $args = array_merge(array(
    'label' => $plural,
    ),$args);

    register_taxonomy($name, $post_type, $args);

    });
    };