Create Dynamic Custom Post Types in WordPress

You are here : Home / Create Dynamic Custom Post Types in WordPress

Custom post types & custom fields are widely used at our company and without these we can’t imagine a website other than a blog.

We don’t use any plugin to create custom post types  because of following reasons.

  • To avoid unnecessary dependencies on third party plugins.
  • Errors in upcoming release of the plugin can affect our custom programming and might be bugs on live site.
  • If client uninstall this accidentally after a long period of development which happens sometime.

This guides is about to create dynamic custom post types using procedure & oops programming and we guess after reading it, you’ll never use any plugin because it’s super easy to do.

Procedural Way to Create a Custom Post Types

Procedure oriented programming is preferred if you’re creating a custom post type in theme. You can write it in functions.php located at your installed theme. Below are the steps to understand it easily.

  • Step 1: Make sure wordpress recognize your function on load so we use “init” action to register our function.
  • Step 2: now in the definition of function ‘create_custom_post_type’, we can register as many as custom post type we need.

    Note : If we’re creating custom post type to save some private data, don’t make it ‘public’=>true and not need for ‘has_archive’=>true if custom post type is not public.

OOPS Way to Create a Custom Post Types

Object oriented programming is preferred if you’re creating a custom post type using plugin. Below is “Custom_Posts” class which we use for our projects.

Now you need to just initialized this object with your new custom post settings. Below is example code to create a SLIDES custom post type.

Conclusion

Adding too many custom post types is not a good practice because that’s can affect your speed of database transactions. Some of developers prefer a dedicated category of the posts instead of a new custom post types which is not a good idea. If you don’t want to make your custom post type public, I’d prefer a new custom table instead of a new custom post type.

 Create Dynamic Custom Post Types in Wordpress

Flipper Code

We have been building WordPress Plugins at flipper code since 2008. We follow wordpress coding standard that ensures we deliver the excellent wordpress plugins and services.

More Posts - Website

Follow Me:
twitter Create Dynamic Custom Post Types in Wordpressfacebook Create Dynamic Custom Post Types in Wordpressgoogleplus Create Dynamic Custom Post Types in Wordpress

Customize Product according to your requirements?

We will be glad to discuss any of your needs related to our wordpress plugins . if any of functionality you'd like to see in products, you can reach us by via email hello@flippercode.com.