• After searching I came with a solution to get the columns in admin sortable (custom post type with meta boxes). First of all, there is nothing to be found about this topic on the codex (about the manage_edit-${post_type}_sortable_columns filter)!

    And now my question. The tutorials all talk about 2 filter’s that need to be set 1) 1 function hooked to manage_edit-${post_type}_sortable_columns filter 2) A second function hooked to either pre_get_posts or request.

    But I found out that the sorting works fine without the second function? This is what I use in my theme functions.php and as you can see the second function is commented:

    <?php
    function wpf_set_quote_sortable_columns($columns) {
    	$columns['person'] = 'person';
    	$columns['slug'] = 'slug';
    	$columns['content'] = 'content';
    
    	return $columns;
    }
    add_filter('manage_edit-quote_sortable_columns', 'wpf_set_quote_sortable_columns');
    
    /*
    function wpf_set_quote_column_orderby($query) {
    	if (!is_admin()) return;
    
    	$orderby = $query->get('orderby');
    
    	if ('person' == $orderby) {
    		$query->set('meta_ket', 'person_sort');
    		$query->set('orderby', 'meta_value_num');
    	}
    }
    add_filter('pre_get_posts', 'wpf_set_quote_column_orderby');
    */

    So I would like to have the best way to sort my custom meta’s. Is the above the right way without the second commented function?

  • The topic ‘Sortable columns (for custom meta post value's)’ is closed to new replies.