[wp-trac] [WordPress Trac] #35416: List children pages of another (in dashboard)

WordPress Trac noreply at wordpress.org
Mon Jul 10 08:43:24 UTC 2017


#35416: List children pages of another (in dashboard)
-------------------------------+---------------------------------
 Reporter:  selnomeria         |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:  ui, administration
-------------------------------+---------------------------------

Comment (by tazotodua):

 here is solution.
 it's good if you added as a patch, because i am not familiar with adding
 patch in core myself...


 {{{
 add_action('init', 'parented_posts_initialize',11);
 function parented_posts_initialize(){
         $p_types = array('post','page'); //get_post_types()
         $parented_post_types =
 apply_filters('parented_posts_filter',$p_types );
         foreach($parented_post_types as $each){
                 add_filter('manage_edit-'.$each.'_columns',
 'create_parented_column');
                 add_action('manage_'.$each.'_posts_custom_column',
 'parented_column_func', 10, 2 );
                 add_filter('manage_edit-'.$each.'_sortable_columns',
 'make_parent_column_sortable' );
         }
 }

 function create_parented_column($columns) {
     $columns['parents'] =__('parents');
     return $columns;
 }

 function parented_column_func( $column_name, $post_id ) {
     if ( 'parents' != $column_name )        return;
     //Get number of parents from post meta
     $parentId = wp_get_post_parent_id( $post_id ) ;
         $parent_p= get_post($parentId);
         if($parentId != $post_id && $parentId !=0){
                 $url =  $_SERVER['REQUEST_URI'];
                 $url =  add_query_arg('parent_id', $parentId, $url );
                 $url =  add_query_arg('orderby', 'parent', $url );
                 echo '<a href="'.$url.'">'.$parent_p->post_name.'</a>';
 return;
         }
     echo ($finalParent);
 }

 function make_parent_column_sortable( $columns ) {
     $columns['parents'] = 'parent';   // to remove:
 unset($columns['date']);
     return $columns;
 }

 add_action( 'pre_get_posts', 'my_slice_orderby' );
 function my_slice_orderby( $query ) {
     if( ! is_admin() )          return;
         global $pagenow;
         if ( ( $pagenow == 'edit.php' ) ) {     // && ( 'slices' ==
 $query->get( 'orderby'))
                 if(isset($_GET['parent_id'])){
                         $query->set('post_parent', (int)
 $_GET['parent_id'] );
                 }
         }
 }
 }}}


 user can use filter to add his desirable custom filter:


 {{{
 add_filter('parented_posts_filter', 'myparented_fitlers',10,1);
 function myparented_fitlers($post_types=array()){
         return array_merge($post_types, array('my_custom_type') );
 }

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35416#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list