0

Hello WordPress community! I modified an existing meta box which is page_attributes. I grafted it to the articles and it allows me to give an order to the posts. I want to add the column to the postslistings in the Wordpress backoffice. I used the Admin columns plugin and the column displays fine. I want the ability to sort items in ascending or descending order of value. But it does not work. Here is my code

function eloi_order_column_register_sortable( $columns ) {
    $columns['62a9d32255c290'] = 'Ordre affichage'; // CSS ID generate by Admin columns plugins
     
    return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'eloi_order_column_register_sortable' );

function order_column_orderby( $vars ) {
   if ( isset( $vars['orderby'] ) && '62a9d32255c290' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
                'meta_key' => 'pageparentdiv', // meta box id : view file wp-includes/meta-box.php line 1522 
                'orderby' => 'meta_value',
                'order' => 'DESC'
        ) );
    }
     
    return $vars;
}
add_filter( 'request', 'order_column_orderby' );

1
  • Are you not using the post's menu_order property to set ordering? WordPress has custom sorting built-in, there's no need to use a meta key. Jun 17 at 7:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.