Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need a second set of eyes, because its late and I can't see this anymore.

Why won't this save? What am I missing?

/****************************************/
// 1. Custom Post Type Registration (Football Tips)

add_action( 'init', 'create_football_tip_postype' );

function create_football_tip_postype() {

$labels = array(
'name' => _x('Football Tips', 'post type general name'),
'singular_name' => _x('Football Tip', 'post type singular name'),
'add_new' => _x('Add New', 'tips'),
'add_new_item' => __('Add New Tip'),
'edit_item' => __('Edit Tip'),
'new_item' => __('New Tip'),
'view_item' => __('View Tip'),
'search_items' => __('Search Tips'),
'not_found' =>  __('No tips found'),
'not_found_in_trash' => __('No tips found in Trash'),
'parent_item_colon' => '',
);

$args = array(
'label' => __('Tips'),
'labels' => $labels,
'public' => true,
'can_export' => true,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array( "slug" => "tips" ),
'supports'=> array('title', 'thumbnail', 'excerpt', 'editor') ,
'show_in_nav_menus' => true,
'taxonomies' => array( 'tf_tipcategory', 'post_tag')
);

register_post_type( 'tf_tips', $args);

}



// 2. Custom Taxonomy Registration (Football Tip Types: Win/Loss)

function create_tipcategory_taxonomy() {

$labels = array(
    'name' => _x( 'Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Category', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Categories' ),
    'popular_items' => __( 'Popular Categories' ),
    'all_items' => __( 'All Categories' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Category' ),
    'update_item' => __( 'Update Category' ),
    'add_new_item' => __( 'Add New Category' ),
    'new_item_name' => __( 'New Category Name' ),
    'separate_items_with_commas' => __( 'Separate categories with commas' ),
    'add_or_remove_items' => __( 'Add or remove categories' ),
    'choose_from_most_used' => __( 'Choose from the most used categories' ),
);

register_taxonomy('tf_tipcategory','tf_tips', array(
    'label' => __('Tip Category'),
    'labels' => $labels,
    'hierarchical' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tip-category' ),
));

}

add_action( 'init', 'create_tipcategory_taxonomy', 0 );


// 3. Show Columns

add_filter ("manage_edit-tf_tips_columns", "tf_tips_edit_columns");
add_action ("manage_posts_custom_column", "tf_tips_custom_columns");

function tf_tips_edit_columns($columns) {

$columns = array(
    "cb" => "<input type=\"checkbox\" />",
    "_category" => "Category",
    "_date" => "Tip Date",
    "_league" => "League",
    "_hometeam" => "Home Team",
"_awayteam" => "Away Team",
"_tip" => "Tip",
"_odd" => "Odd",
"_result" => "Result",
"_score" => "Score",
   );

return $columns;

}

function tf_tips_custom_columns($column) {

global $post;
$custom = get_post_custom();
switch ($column)

    {
        case "_category":
            // - show taxonomy terms -
         /*   $tipcats = get_the_terms($post->ID, "tf_tipcategory");
            $tipcats_html = array();
            if ($tipcats) {
                foreach ($tipcats as $tipcat)
                array_push($tipcats_html, $tipcat->name);
                echo implode($tipcats_html, ", ");
            } else {
            _e('None', 'themeforce');;
            } */
        break;
    case "_date":
    echo $custom["tf_tips_date"][0];
        break;
        case "_league":
    echo $custom["tf_tips_league"][0];
        break;
    case "_hometeam":
    echo $custom["tf_tips_home_team"][0];
        break;
    case "_awayteam":
    echo $custom["tf_tips_away_team"][0];
        break;
    case "_tip":
    echo $custom["tf_tips_tip"][0];
        break;
    case "_odd":
    echo $custom["tf_tips_odd"][0];
        break;
    case "_result":
    echo $custom["tf_tips_result"][0];
        break;
    case "_score":
    echo $custom["tf_tips_score"][0];
        break;

    }
}


// 4. Show Meta-Box

add_action( 'admin_init', 'tf_tips_create' );

function tf_tips_create() {
add_meta_box('tf_tips_meta', 'Tips', 'tf_tips_meta', 'tf_tips', 'normal', 'default');
}

function tf_tips_meta () {

// - grab data -

global $post;
$custom = get_post_custom($post->ID);
$date = $custom["tf_tips_date"][0];
$league = $custom["tf_tips_league"][0];
$hometeam = $custom["tf_tips_home_team"][0];
$awayteam = $custom["tf_tips_away_team"][0];
$tip = $custom["tf_tips_tip"][0];
$odd = $custom["tf_tips_odd"][0];
$result = $custom["tf_tips_result"][0];
$score = $custom["tf_tips_score"][0];    


// - security -

echo '<input type="hidden" name="tf-tips-noncename" id="tf-tips-noncename" value="' .
wp_create_nonce( 'tf-tips-nonce' ) . '" />';


// - output -

?>
<div class="tf-meta">
    <ul>
        <li><label>Tip Date</label><input name="tf_tips_date" value="<?php echo $date; ?>" /></li>
        <li><label>League</label><input name="tf_tips_league" value="<?php echo $league; ?>" /></li>
        <li><label>Home Team</label><input name="tf_tips_home_team" value="<?php echo $hometeam; ?>" /></li>
        <li><label>Away Team</label><input name="tf_tips_away_team" value="<?php echo $awayteam; ?>" /></li>
    <li><label>Tip</label><input name="tf_tips_tip" value="<?php echo $tip; ?>" /></li>
    <li><label>Odd</label><input name="tf_tips_odd" value="<?php echo $odd; ?>" /></li>
    <li><label>Result</label><input name="tf_tips_result" value="<?php echo $result; ?>" /></li>
    <li><label>Score</label><input name="tf_tips_score" value="<?php echo $score; ?>" /></li>
    </ul>
</div>
<?php
}


// 5. Save Data

add_action ('save_post', 'save_tf_tips', 10, 2);

function save_tf_tips(){

global $post;

//skip auto save
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    return $post->ID;
}

if ( get_post_type($post) != 'tf_tips')
    return $post->ID;

// - still require nonce

if (isset($_POST['tf-tips-noncename'])){
    if ( !wp_verify_nonce( $_POST['tf-tips-noncename'], 'tf-tips-nonce' )) 
       return $post->ID;
}
else{ return $post->ID; }

if ( !current_user_can( 'edit_post', $post->ID ))
    return $post->ID; 

// - convert back to unix & update post

if(isset($_POST["tf_tips_date"])){
    $updatedate = $_POST["tf_tips_date"];
    update_post_meta($post->ID, "tf_tips_date", $updatedate);
}

if(isset($_POST["tf_tips_league"])){
    $updateleague = $_POST["tf_tips_league"];
    update_post_meta($post->ID, "tf_tips_league", $updateleague);
}

if(isset($_POST["tf_tips_home_team"])){
    $updatehometeam = $_POST["tf_tips_home_team"];
    update_post_meta($post->ID, "tf_tips_home_team", $updatehometeam);
}

if(isset($_POST["tf_tips_away_team"])){
    $updateawayteam = $_POST["tf_tips_away_team"];
    update_post_meta($post->ID, "tf_tips_away_team", $updateawayteam);
}

if(isset($_POST["tf_tips_tip"])){
    $updatetip = $_POST["tf_tips_tip"];
    update_post_meta($post->ID, "tf_tips_tip", $updatetip);
}

if(isset($_POST["tf_tips_odd"])){
    $updateodd = $_POST["tf_tips_odd"];
    update_post_meta($post->ID, "tf_tips_odd", $updateodd);
}

if(isset($_POST["tf_tips_result"])){
    $updateresult = $_POST["tf_tips_result"];
    update_post_meta($post->ID, "tf_tips_result", $updateresult);
}

if(isset($_POST["tf_tips_score"])){
    $updatescore = $_POST["tf_tips_score"];
    update_post_meta($post->ID, "tf_tips_score", $updatescore);
}

}
share|improve this question
1  
TL;DR, see sscce.org, the tips there are useful for troubleshooting as well. –  brasofilo Sep 23 '13 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.