Custom Post Type With Different Views

We are rebuilding our website in WordPress and are trying to figure out the best solution to display a different views of the same product with unique meta data.

For example, let’s say that Property is the post type. We would like to display several different views (completed (built), for sale, and for rent.)

Each would have slightly different text and custom fields that display based on what the user is looking at with 3 different URL patterns:


A Property can fall into one or many different views – (both for sale and for rent for example.)

Ideally, we would have one post type and the views would display the information according to what view you are looking for (rather than duplicate the content and any translations 3 times). I know that this can be achieved with 3 separate custom post types, but is possible to do this with one while maintaining separate meta data for each view?

To complicate things we are using WPML for translation. This is one of the reasons why having one post type would be preferred. Would a plugin like Yoast still be able to apple unique meta data for the separate views?

Solutions Collecting From Web of "Custom Post Type With Different Views"

For example, let’s say that Property is the post type. We would like
to display several different views (completed (built), for sale, and
for rent.)

Sure. Just make Completed, For Sale, and For Rent taxonomies for the Property post type.
Look into WP_Rewrite class, too, and you can get greater control over url permalink structure.

One possible solution is to add a metadata field to your post indicating the status (i.e. completed, for sale or for rent). Then in your template file you call get_post_meta and show the content depending on the status. An added bonus of this approach is that you’ll be able to generate post listings based on the status.

To add the metadata with plugins you could use Advanced Custom Fields to add a field “status” to your posts. If you want to do so programmatically, I can recommend an excellent video tutorial by Bobby.

Another solution, quite less elegant though, would be to use post formats (search the codex for post formats). In that case you would not need to add a custom metadata field. Note that wordpress does not allow to generate custom post formats, so you’ll have to map three of the nine predefined to the three possible statuses of your properties. A good video tutorial by Alessandro shows how to deal with post formats.
By adopting this approach, you need to manually set the post format in your dashboard so the right template is rendered (e.g. aside => completed, gallery => for sale and link => for rent).