Monday, August 5, 2013

Custom post types in wordpress

Today I've upgraded majority of my localhost wp blogs to wp 3.6: http://codex.wordpress.org/Version_3.6#Scripts.2C_External_Libraries
I've also been given a new task from someone on skype.  The task is to create a custom post type that works as the default post type but also has a custom meta box (named image) with input fields for color, size, download link.  This is a simple sketch as to what I want it to look like this:
Okay so I've messed with custom post types before but I forget how to get started with them and can't find a post on here about it so I'm just gunna take some notes on this: http://codex.wordpress.org/Post_Types

First off, custom post types get registered using the register_post_type func: http://codex.wordpress.org/Function_Reference/register_post_type
register_post_type(Name, Args);

This function must be hooked before the admin_menu and after_setup_theme hooks.  It's recommended that the init hook is used.  At the end of today using what I've read so far this is the code I've made for the custom post type: http://pastebin.com/nxvqPFu5

Now that I've learned to add the custom post type I can focus on adding a custom meta box tomorrow.

No comments:

Post a Comment