[wp-trac] [WordPress Trac] #47994: The additions of a new wp_posts table columns called post_level and post_patriarch
WordPress Trac
noreply at wordpress.org
Fri Sep 6 23:29:49 UTC 2019
#47994: The additions of a new wp_posts table columns called post_level and
post_patriarch
-------------------------+-----------------------------
Reporter: samjco | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
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
SELECT p.*
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
SELECT p.*
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47994>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list