background preloader

Post Type / CPT

Facebook Twitter

Meta capabilities for custom post types. While I was fiddling around with a new plugin that uses custom post types for WordPress the other day, I ran into a small issue that I hadn’t noticed before.

Meta capabilities for custom post types

Meta capabilities for custom post types were not being automatically mapped, so I couldn’t have granular control over permissions. At first, I was a bit disappointed that this wasn’t taken care of because this would be a major blow to my plugin. However, I soon learned this could be considered a great feature rather than a bug. Andrew Nacin mentioned that we’d need to “roll our own handling” for capabilities using the map_meta_cap hook. This hook gives you control over the meta capabilities as well as the power to step outside of the WordPress way of doing things. Before reading on, please note that this is only an issue/feature if you’re using custom capabilities for your post types. What are meta capabilities? Generate WordPress Post Type. Let’s make a WordPress Widget that displays our Custom Post Types. So I had a question from one my readers: “How can I add a Latest Listing widget in the sidebar“, which really translates to “How do we create a WordPress Widget?”

Let’s make a WordPress Widget that displays our Custom Post Types

Well, a widget that pulls our Custom Post Types. So I did a bit of research, and it turns out – that it’s not hard at all. We just need to know the basics of the Widgets API, plus a bit of PHP. This tutorial was written using Realty, since it’s already using Custom Post Types for the House Listings. So I am trying to shoot 3 birds in one stone: 1) To answer my reader’s question, 2) to add some functionality to the theme, as well as 3) learn something new. So ready to start coding? Create the basic Widget In your functions.php file, write the following code: The above code sets up our widget class.

Now, notice above that we have a method __construct() – which just register’s our widget id, a name and a description. So all we need to create is 2 more methods: form() and widget(). The form() method The widget() method. A Guide to WordPress Custom Post Types: Taxonomies, Admin Columns, Filters and Archives. Custom Post Type Snippets to make you smile. So it’s friday, I’ve been coding all day and I thought I’d share some of the cool snippets I’ve come across and/or developed today.

Custom Post Type Snippets to make you smile

I’ve mostly been working with Custom Post Types and Taxonomies, so let me share some of that goodness. Let’s geek out in a bit, but first let me show you why this is cool, be sure to click the image, so you can see which functionality I’ve added to the otherwise boring custom posts overview screen: Click for large version Add columns to the overview page for a Custom Post Type So you’ll want to add some columns to your post type’s overview page, or remove some. Be sure to always leave the cb column in there or your mass edit / delete functionality will not work. Give these new columns some content Now let’s fill these new columns with some content from the custom post type: Make these new columns sortable Now this extra info is cool, I bet you want to sort by it, that’s as simple as this: WordPress custom post types. The Complete Guide To Custom Post Types.

WordPress has been gaining a foothold in the general content management system (CMS) game for a few years now, but the real breakthrough was the custom post type mechanism which allows for the creation of a wide variety of content.

The Complete Guide To Custom Post Types

Let’s take a look at how this came to be and all the options that this great functionality offers. 1Some of the custom post types you can create in WordPress. What It Used To Be Like In practice, custom post types have been around for a long time, more specifically since February 17, 2005, when WordPress 1.5 added support for static pages, creating the post_type database field. The wp_insert_post() function has been around since WordPress 1.0, so when the post_type field was implemented in 1.5, you could simply set the post_type value when inserting a post. By version 2.8, the register_post_type() function and some other helpful things were added to the nightly builds, and when 2.9 came out, the functions became available to everyone. Post Types. Languages: English • 日本語 Português do Brasil • Nederlands • Slovenčina • 中文(简体) • (Add your language) WordPress can hold and display many different types of content.

Post Types

A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type. WordPress 3.0 gives you the capability to add your own custom post types and to use them in different ways.