WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an unusual situation where I need to make the built-in post type 'page' non-hierarchical.

I printed the post type object with var_dump(get_post_type_object('page')); die; and I got this:

object(stdClass)#164 (26) {
  string(0) ""
  string(4) "page"
  string(16) "post.php?post=%d"

How might I go about modifying the post-type object so that ["hierarchical"]=>bool(false)?

share|improve this question
As a first reaction I really have no idea what you want to accomplish, which makes me think this question could be better if you give some examples and explain why you would want to change the post type object - maybe there is a better way to do what you want? – miahelf Apr 17 '12 at 5:38
I have an existing site wherein there are 300+ pages. The content editors wish to disable the ability to create child pages for two reasons: 1) The content of pages is almost never related, and 2) Some less experienced editors have been creating child pages which are not displayed in the theme, causing that content to be "lost". The only other option I explored was to simply hide the "page parent" dropdowns in the quickedit view and the edit screen, but that seems kinda hacky as it involves css rather than filters. – Niels Apr 19 '12 at 1:11
up vote 2 down vote accepted

This is a pretty late answer, but I was looking to do something similar and figured it out. I wanted to get nav_menu_items into an RSS feed, which required changing the built in nav_menu_item post type property publicly_queryable.

Anyway, it was actually pretty simple, here's a generic function to do it:

function change_wp_object() {
  $object = get_post_type_object('post_type');
  $object->property = true;

And that's it. I've got it in a plugin. If you want to see the list of available properties to change, throw in

echo '<pre>'.print_r($object, 1).'</pre>';

to get a nicely formatted output of all the properties.

In your case you'd use

$object-> hierarchical = false;

Hope that helps someone!

share|improve this answer

As far as I can tell, there is no (good) way to change the core post types. The alternative of course is to make your own custom post type. If you have a bunch of posts that are the core post type of page, you could run a MySQL query to convert them all at once to the new post type, once created, if you need to. Or, you could possibly change the way your theme displays a list of pages.

To make a new post type that is not hierarchical:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'nonhierarchical_page',
            'labels' => array(
                'name' => __( 'NHPages' ),
                'singular_name' => __( 'NHPage' )
            'public' => true,
            'hierarchical' => false
share|improve this answer
This isn't going to work unfortunately as a lot of other infrastructure relies on the current setup. – Niels Apr 19 '12 at 1:06

Your Answer


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.