WordPress custom post with custom fields


In the wordpress there need to create certain code that can create the custom post. The custom post help in custom development.
With the help custom post you easily add the different module like portfolio, books, movie etc. The wordpress provides to you various inbuilt functions that can increase you development faster and robust. Today i show you just management of simple portfolio items. In this context i show you with custom post type you can add the custom text box also. That custom text help them to refining your post. With the help of these custom field you can filter your matter better. I just show the below code.


add_action(‘init’, ‘portfolio_register’);

function portfolio_register() {

$labels = array(
‘name’ => _x(‘My Portfolio’, ‘post type general name’),
‘singular_name’ => _x(‘Portfolio Item’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘portfolio item’),
‘add_new_item’ => __(‘Add New Portfolio Item’),
‘edit_item’ => __(‘Edit Portfolio Item’),
‘new_item’ => __(‘New Portfolio Item’),
‘view_item’ => __(‘View Portfolio Item’),
‘search_items’ => __(‘Search Portfolio’),
‘not_found’ =>  __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item_colon’ => ”

$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/article16.png’,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)

register_post_type( ‘portfolio’ , $args );

register_taxonomy(“Skills”, array(“portfolio”), array(“hierarchical” => true, “label” => “Skills”, “singular_label” => “Skill”, “rewrite” => true));

add_action(“admin_init”, “admin_init”);

function admin_init()
add_meta_box(“year_completed-meta”, “Year Completed”, “year_completed”, “portfolio”, “side”, “low”);
add_meta_box(“credits_meta”, “Design &amp; Build Credits”, “credits_meta”, “portfolio”, “normal”, “low”);

function year_completed(){
global $post;
$custom = get_post_custom($post->ID);
$year_completed = $custom[“year_completed”][0];
<input name=”year_completed” value=”<?php echo $year_completed; ?>” />

function credits_meta() {
global $post;
$custom = get_post_custom($post->ID);
$designers = $custom[“designers”][0];
$developers = $custom[“developers”][0];
$producers = $custom[“producers”][0];
<p><label>Designed By:</label><br />
<textarea cols=”50″ rows=”5″ name=”designers”><?php echo $designers; ?></textarea></p>
<p><label>Built By:</label><br />
<textarea cols=”50″ rows=”5″ name=”developers”><?php echo $developers; ?></textarea></p>
<p><label>Produced By:</label><br />
<textarea cols=”50″ rows=”5″ name=”producers”><?php echo $producers; ?></textarea></p>



//add_meta_box( $id, $title, $callback, $page, $context, $priority );

global $post;

$custom = get_post_custom($post->ID);

add_action(‘save_post’, ‘save_details’);

function save_details(){
global $post;

update_post_meta($post->ID, “year_completed”, $_POST[“year_completed”]);
update_post_meta($post->ID, “designers”, $_POST[“designers”]);
update_post_meta($post->ID, “developers”, $_POST[“developers”]);
update_post_meta($post->ID, “producers”, $_POST[“producers”]);

add_action(“manage_posts_custom_column”,  “portfolio_custom_columns”);
add_filter(“manage_edit-portfolio_columns”, “portfolio_edit_columns”);

function portfolio_edit_columns($columns){
$columns = array(
“cb” => “<input type=’checkbox’ />”,
“title” => “Portfolio Title”,
“description” => “Description”,
“year” => “Year Completed”,
“skills” => “Skills”,

return $columns;
function portfolio_custom_columns($column){
global $post;

switch ($column) {
case “description”:
case “year”:
$custom = get_post_custom();
echo $custom[“year_completed”][0];
case “skills”:
echo get_the_term_list($post->ID, ‘Skills’, ”, ‘, ‘,”);

//’supports’ => array(‘title’, ‘editor’, ‘thumbnail’);


register_post_type( ‘portfolio’ , $args );



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s