1

everyone!

I'm having trouble trying to update WordPress core 'post' registered arguments to improve a functionality in my website. Specifically, I want to be able to have a hierarchy between my posts so I can set parents and childs for posts. Creating a custom post type to create this won't help me as all my content is based in posts.

By default, WordPress allows this only for Pages post type.

Recently, WordPress added a neat function to modify arguments from an already registered post type, called "register_post_type_args". This should work both for default and custom post types. I have come accross this code and modified to add what I need: Change capability type of post type registered by plugin

The results are below. However, when I add this to my functions.php, somehow, I can't get this to work. My website returns a "Parse error: syntax error, unexpected end of file".

add_filter( 'register_post_type_args', 'allow_post_hierarchy' , 10, 2 );

function allow_post_hierarchy( $args, $post_type ){

 // Do not filter any other post type
 if ( 'post' !== $post_type ) {

     // Give other post_types their original arguments
     return $args;

 }

 // Change the capability_type of the "custom-css-js" post_type
    $args = array(
        'hierarchical' => 'true',
    );

  // Give the custom-css-js post type it's arguments
  return $args;

}

Does anyone have any idea why this is happening? I appreciate your input. Thanks!

  • WordPress doesn't seem to like having the post post type configured as hierarchical. When I did it, the menu link for posts changed to Pages. It's probably better to use categories, tags, or a custom taxonomy – Dave Romsey Oct 20 '16 at 20:37
  • Aren't you deleting all the other elements of $args this way (since you redefine the array)? Try $args['hierarchical'] = 'true'; instead. – Dmitriy Gamolin Oct 20 '16 at 21:09
  • Changed it, still can't get it to work. @DaveRomsey, I also came to a code which changes my posts to Pages in the menu, however the hierarchical option still doesn't work. :( – Alan Niemies Oct 21 '16 at 2:47

Your Answer

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

Browse other questions tagged or ask your own question.