0

Would something like this work? Am I missing anything?

function page_attributes_for_posts() {
    register_post_type('job-bank-posts',
        $args = array(
            'hierarchical' => true,
            'supports' => 'page-attributes'
        );
    );
};
add_action ('init', 'page_attributes_for_posts');

This is one of the sources I used: https://developer.wordpress.org/reference/functions/register_post_type/

3 Answers3

1

Maybe a complete example could be helpful:

 function create_job_bank_posts() {
  register_post_type( 'book',
    array(
      'labels' => array(
        'name' => __( 'Job Bank Posts' ),
        'singular_name' => __( 'Job Bank Post' ),
        'add_new' => _x('Add Job Bank Post', 'Job Bank Post'),
        'add_new_item' => __('Add Job Bank Post'),
        'edit_item' => __('Edit Job Bank Post'),
        'new_item' => __('New Job Bank Post'),
        'view_item' => __('View Job Bank Post'),
        'search_items' => __('Search Job Bank Post'),
        'not_found_in_trash' => __('Not found in trash'),
      ),
      'public' => true,
      'menu_icon' => 'your-dashicon',
      'rewrite' => array( 'slug' => 'job_bank_posts', 'with_front' => true ),
      'menu_position' => 3,
      'hierarchical' => true,
      'supports' => array(
                'title',
                'page-attributes',
                'thumbnail',
                'editor',
                'excerpt',
                'author',
                'comments',
                'custom-fields',
            ),
    )
  );
}
add_action( 'init', 'create_job_bank_posts' );
hhh
  • 394
  • 2
  • 15
0

Maybe that will help, they added the parent feature for post https://make.wordpress.org/core/2021/02/10/introducing-new-post-parent-related-functions-in-wordpress-5-7/

This plugin works perfect to make posts as parent https://wordpress.org/plugins/add-hierarchy-parent-to-post/

Tanya Nami
  • 66
  • 8
  • We use WordPress version 5.8.4, and it appears that the option to set a Parent for a post is still not available. This link might be more about identifying whether a "post" has a parent, not actually enabling the ability to set a parent. Also, it appears WordPress may refer to pages as "posts," as from reading this: https://wordpress.org/support/article/post-types/ –  Aug 26 '22 at 13:19
  • In this case plugin will help you, it works perfect! Please, see my answer I updated it – Tanya Nami Aug 26 '22 at 15:46
  • also you can take a look here if you don't want plugins https://stackoverflow.com/questions/10750931/wordpress-how-to-add-hierarchy-to-posts/49359200#49359200 – Tanya Nami Aug 26 '22 at 15:50
-1

Forgive me if this isn't quite what you are after. OK, I managed to achieve something like this purely using WordPress's built-in Permalink Settings. The other issue with this quick method is that you will no longer have the use of categories. But its works well for us.

  1. go to wp-admin/options-permalink.php

  2. Select: Custom Structure

  3. you'll want a structure like the following: /about/%category%/%postname%/

  4. The category you choose for each post will become the parent for all posts under that category.

  5. I then create an extra file in my template called 'periodic-category.php' :

`<?php if (!defined('ABSPATH')) exit;
/*
Template Name: Periodic category
*/

get_header();

echo $app->templates()->get('pages/category')->render([
    'post' => $post,
    'parts' => [
        'breadcrumbs' => $app->templates()->get('layout/breadcrumbs')->render(),
        'left_menu' => $app->templates()->get('layout/menu-left')->render(['tax' => 'periodic', 'post' => $post])
    ]
]);

get_footer();
`
  1. You then want to create a page for each category and select periodic-category.php as the template in the post editor.

  2. When ever you create a new post and select a category, it will be listed when you visit the category page.

The answer above provides you with the opportunity to add multiple parents pages for posts. If you simply want one parent page, then it is as follows:

  1. From the Dashboard, choose Pages→Add New. ...
  2. Type a name for the page in the text box toward the top of the page. ...
  3. Leave the text box blank. ...
  4. Click the Publish button. ...
  5. Choose Settings→Reading. ...
  6. From the Posts Page drop-down list, choose the page you just created. Done

I'm happy to share files etc if that is permitted here. Please forgive me as i am new. So happy to learn from others.

netooze
  • 1
  • 3
  • We would like to keep Categories, so this won't work, but thank you for the suggestion and posting something that worked for you. –  Aug 26 '22 at 13:14
  • This is a specific answer that worked for the author but is not a correct way to add parents to wordpress posts. – Vinay Jain Aug 27 '22 at 12:31