Make WordPress Core

Opened 5 years ago

#47994 new enhancement

The additions of a new wp_posts table columns called post_level and post_patriarch

Reported by: samjco's profile samjco Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords:
Focuses: Cc:


Many user are looking for an easy solution to sort table by page children.
I understand their are functions like get_children, pre_get_posts, get_posts, wp_query.

But if I wanted to extract the children directly from the db table wp_posts, their is no easy way.

So I am suggest the Core team to add in an additional column: post_level.
This is already noticed with the post list table's html row/td as a class (level-0) so it should be in the table.

//Get all 1st generations of post based on 2 parents who are cousins
FROM $wpdb->posts p 
WHERE p.post_level = 1 
AND p.post_parent = 123 OR p.post_parent = 345)

//Get all 2nd generation pages of parent post id 1
FROM $wpdb->posts p 
WHERE p.post_level = 2 
AND p.post_patriarch = 1

post_level depends on what level of Parent (0), Child (1) or Grandchild(2) or GreatGrandChild (3) a page is within the Hierarchy.

post_patriarch (or lack of a better word) is always the level 0 parent ID

This should also be consider for other tables as well(e.g menu_level)

I hope this make sense.

Change History (0)

Note: See TracTickets for help on using tickets.