0

I want to be able to select a parent post when i create a new post. I assume it should be easy just to make the 'page attributes' admin widget to work similarly for posts too. The use case is for this site: thedevs.org where i want to enable people to post projects then later on make new posts that are children to a project post and would be listed under the parent post. I am slightly new to wordpress but i play around with php quite easily. A working plugin or code snippet would help.

1

3 Answers 3

1

The parameter that controls post-type hierarchy is called 'hierarchical', and is set when the post type is registered via register_post_type(). WordPress core registers the 'post' post-type with 'hierarchical' => false.

To override this setting, refer to this question.

3
  • Thank you, but sorry, i have no idea how post-type works or where i should plug in the functions to see the magic. Please help me like a 2 year old (in wordpress)...
    – Timothy
    Mar 5, 2013 at 3:04
  • NOW, I have been able to create a new custom post type but I still dont see the 'page attributes' admin widget in order to choose parent. How do i make this happen?
    – Timothy
    Mar 5, 2013 at 4:52
  • That's a separate question from your OP. Please start a new question, or else edit your question to change the scope, and paste in your register_post_type() code. Mar 5, 2013 at 12:41
0

Adding this code on my ..mytheme/functions.php file sort of worked for me:

            /* Register Custom Post Type for Projects*/
            add_action('init', 'project_post_type_init');
            function project_post_type_init() {
              $labels = array(
                'name' => _x('My Projects', 'post type general name'),
                'singular_name' => _x('Project', 'post type singular name'),
                'add_new' => _x('Add New', 'Project'),
                'add_new_item' => __('Add New Project'),
                'edit_item' => __('Edit Project'),
                'new_item' => __('New Project'),
                'view_item' => __('View Project'),
                'search_items' => __('Search Projects'),
                'not_found' =>  __('No Projects found'),
                'not_found_in_trash' => __('No Projects found in Trash'),
                'parent_item_colon' => __('Post'),
                'parent' => __('Post'),
              );
              $args = array(
                'labels' => $labels,
                'public' => true,
                'publicly_queryable' => true,
                'show_ui' => true, //false - to hide from the admin area menu
                'rewrite' => true,
                'query_var' => true,
                'capability_type' => 'post',
                'hierarchical' => true, //allow parent pages
                'show_in_nav_menus' => false,
                'menu_position' => 1000,
                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'page-attributes')
              );
              register_post_type('project',$args);
            }
0

Just go through below Documentation and add the function in your functions.php https://codex.wordpress.org/Function_Reference/add_post_type_support

1
  • Please improve your answer. While the link might answer the question, you should include the essential parts of the answer here and only provide the link for reference.
    – Gabriel
    Feb 19, 2016 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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