I have a custom post type for portfolio. To create one, you need to create a page with a particular template that i'm making, named page-portfolio.

Now, a portfolio post has custom fields as well. But, how can i make a custom field that is displayed in the post only if i select the 'portfolio' template ? That is, a custom field tied to the usage of the portfolio template ?


This is confusing you're mixing up the terminology of WordPress. A custom post type acts like a post and not a page. If you have a custom post type called "portfolio" and use the proper template hierarchy, you don't have to do anything special. But you will need to name it single-portfolio.php and not page-portfolio.php.


If on the other hand, if you simply want to use "page" templates ( I think that is what you mean) you will need to write a conditional to display the post meta for only the page-portfolio.php.

The logic is along the lines of:

if (is_page_template('page-portfolio.php')) 

Your default page most likely already has the_meta(); though so you will most likely want to use get_post_meta or get_post_custom so you can have fields specific to your "portfolio".

ps. It's much easier to just use a custom post type (not a page template) for this sort of thing .


  • I probably did not make myself clear. There is a custom post type AND a custom page template in my case. The type is a portfolio item, the page is a showcase of the items. The conditional display is probably what i need though, yes. I'm trying it thanx :) – SpyrosP Jul 23 '11 at 5:35
  • ah was confusing since they seem to have the same name, the is_page_template is probably what you want. – Wyck Jul 23 '11 at 5:38
  • hmm, thinking about it, this actually checks about the template, when displaying that template. I actually want to dynamically create an admin meta box when the portfolio template is selected. – SpyrosP Jul 23 '11 at 23:15

I am currently figuring out a similar problem, I think.

Using the Custom Field Template plugin, you can add different types of fields, including TinyMCE and checkboxes.

This article should help: http://www.designfaire.com/blog/custom-post-types-and-custom-field-template-in-wordpress-3-0-beta-2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.