$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Subpages for Custom Post Type. Does that even exist?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Subpages for Custom Post Type. Does that even exist?

matteradmin9PV0评论

I am running multiple contests (one of which in a really large scale, all-year long) on my e-shop. They all have different rules, different structure so I've created a custom post type 'contest' for that. It suits me well, I've added some custom fields, that are common for all contests (images, date intervals etc.).

My question is, some of those contests might need their own 'subpages' in the future (e.g. full terms, tossing rounds, winners, etc.).

What is the best approach for this? Can I create a new page, add the content and somehow assign it to a specific entity of a custom post type?

I started thinking about this when I realized I want the SEO sitelinks to appear like this (search results):

The contest name | Mysite
• Terms   • Winners
• Tossing rounds

The simple way would be to just create the pages, add "nofollow" to them, but that way only the main contest page would get indexed, which is not what I'm trying to achieve.

I am running multiple contests (one of which in a really large scale, all-year long) on my e-shop. They all have different rules, different structure so I've created a custom post type 'contest' for that. It suits me well, I've added some custom fields, that are common for all contests (images, date intervals etc.).

My question is, some of those contests might need their own 'subpages' in the future (e.g. full terms, tossing rounds, winners, etc.).

What is the best approach for this? Can I create a new page, add the content and somehow assign it to a specific entity of a custom post type?

I started thinking about this when I realized I want the SEO sitelinks to appear like this (search results):

The contest name | Mysite
• Terms   • Winners
• Tossing rounds

The simple way would be to just create the pages, add "nofollow" to them, but that way only the main contest page would get indexed, which is not what I'm trying to achieve.

Share Improve this question asked Dec 18, 2018 at 8:00 Kristián FiloKristián Filo 4316 silver badges20 bronze badges 2
  • 1 Custom post types can be hierarchical and this feature is well-documented. About sitelinks: Google decides (not you) to show them or not depending on the site structure. – Max Yudin Commented Dec 18, 2018 at 9:17
  • I did not know about the 'hierarchical' argument for a custom post type, thank you very much. About sitelinks: Yes, I know this, that is way I was planning to have it welll-structured from the beginning. – Kristián Filo Commented Dec 18, 2018 at 10:01
Add a comment  | 

1 Answer 1

Reset to default 1

When you register post type with register_post_type, you can set hierarchical argument.

hierarchical - (boolean) (optional) Whether the post type is hierarchical (e.g. page).

Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.

Default: false

Note: this parameter was intended for Pages. Be careful when choosing it for your custom post type - if you are planning to have very many entries (say - over 2-3 thousand), you will run into load time issues. With this parameter set to true WordPress will fetch all IDs of that particular post type on each administration page load for your post type. Servers with limited memory resources may also be challenged by this parameter being set to true.

As you can see, its default value is false, so the CPT is not hierarchical. Set it to true, and your CPT will be hierarchical.

Post a comment

comment list (0)

  1. No comments so far