Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set order_by parameter for admin columns to meta_value_num #65

Open
ajuliano opened this issue Jun 29, 2017 · 1 comment
Open

set order_by parameter for admin columns to meta_value_num #65

ajuliano opened this issue Jun 29, 2017 · 1 comment
Milestone

Comments

@ajuliano
Copy link

ajuliano commented Jun 29, 2017

We are using this for all out projects. It's awesome. However, we would love the feature to sort set the order_by parameter for admin columns to meta_value_num.

I saw that there is a // @TODO meta_value_num on line 466. But I couldn't solve the problem to make a pull request. We would have to add another parameter to $sortables to make it work right? I couldn't figure out how to do that in the right manner.

@chood531
Copy link

chood531 commented Sep 4, 2017

@ajuliano - I solved this by doing the following in the extended-cpts.php plugin file.

if ( isset( $orderby['meta_key'] ) ) {
	
	$return['meta_key'] = $orderby['meta_key'];
	$return['orderby'] = 'meta_value';
	
	if(isset($orderby['meta_value_num']) && $orderby['meta_value_num']) {
		$return['orderby'] = 'meta_value_num';	
	}

} else if ( isset( $orderby['post_field'] ) ) {
	$field = str_replace( 'post_', '', $orderby['post_field'] );
	$return['orderby'] = $field;
}

Next, when using the register_extended_post_type function to register a post type, in the admin_cols array item which needs meta_value_num, add a new item to the array:

'admin_cols' => [
    'percent_complete' => [
        'title' => 'Percent Complete',
        'meta_key' => '_percent_complete',
        'meta_value_num' => true
    ]
]

huubl added a commit to huubl/extended-cpts that referenced this issue Mar 8, 2021
Pull request with the solution from @chood531:
johnbillion#65 (comment)

Fixing:  johnbillion#65
huubl pushed a commit to huubl/extended-cpts that referenced this issue Mar 8, 2021
Made a pull request of the solution from @chood531:
johnbillion#65 (comment)

Fixing:  johnbillion#65
@johnbillion johnbillion added this to the 5.0.0 milestone Oct 3, 2021
@johnbillion johnbillion modified the milestones: 5.0.0, 5.1.0 Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants