Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
http://codex.wordpress.org/Post_Types

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')) 
the_meta();

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 .

http://codex.wordpress.org/Custom_Fields#Function_Reference
http://codex.wordpress.org/Function_Reference/is_page_template

share|improve this answer
    
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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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