简体   繁体   中英

WordPress add custom fields to only one post

To keep it simple here's a question: Is it possible to make a single post of custom post type to have a different fields than other posts of this post type?

For example I have a custom post type called "Home page" which has two custom fields:

  • Title
  • Content

I have 3 posts of this post type:

  1. "Header Block" which has title and some content
  2. "About site block" which also has title and content
  3. "Contact us" which has title, and content which is divided into three different columns which I'd prefer to edit in 3 different textareas of my post.

Is there a way to dynamically add these three textarea to the "Contact us" post and only to this post which is a "Home page" type post as first two above.

You can use custom page template and check if template name equal somethings add some fields,For example add some code like this in funtions.php

$template = get_post_meta( $id, '_wp_page_template', true );
if($template == 'Home page'){
   //add fields...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM