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

Issue on class-wp-query.php #216

Open
arnoldpalar opened this Issue May 11, 2017 · 2 comments

Comments

Projects
None yet
1 participant
@arnoldpalar

arnoldpalar commented May 11, 2017

Hi,

Got issue when using ACF plugin and try to order WP_Query() result using custom field as below
$posts_query = new WP_Query(
array (
...
...
'meta_key' => 'release_date',
'orderby' => 'meta_value',
'order' => 'DESC'
)
);
this will result to undeclared variable error on /wp-includes/class-wp-query.php->parse_orderby( $orderby, &$orderbyfields ) (line:1495). below condition will not set the $orderby_clause variable which is the returend variable of the method
...
...
case 'meta_value':
if ( ! empty( $primary_meta_query['type'] ) ) {
$orderby_clause = "meta_value";
$orderbyfields = $orderbyfields . ", CAST({$primary_meta_query['alias']}.meta_value AS {$sql_type}) as meta_value";
} else {
$orderbyfields = $orderbyfields . ", {$primary_meta_query['alias']}.meta_value";
}
break;
...
...

For temporary solution I try to declare the variable before the switch clause as below
$orderby_clause = '';
but I know editing the core scripts is not a good solution.

Is there any better solution or will there be a patch?

Regards,
Arnold.

@arnoldpalar

This comment has been minimized.

Show comment
Hide comment
@arnoldpalar

arnoldpalar May 12, 2017

Found out that solution cannot be applied since it won't order the result.

arnoldpalar commented May 12, 2017

Found out that solution cannot be applied since it won't order the result.

@arnoldpalar

This comment has been minimized.

Show comment
Hide comment
@arnoldpalar

arnoldpalar May 12, 2017

I ended up put the original line from WP as below
case 'meta_value':
if ( ! empty( $primary_meta_query['type'] ) ) {
$orderby_clause = "meta_value";
$orderbyfields = $orderbyfields . ", CAST({$primary_meta_query['alias']}.meta_value AS {$sql_type}) as meta_value";
} else {
$orderbyfields = $orderbyfields . ", {$primary_meta_query['alias']}.meta_value";
$orderby_clause = "{$primary_meta_query['alias']}.meta_value"; //original line from WP
}
break;

arnoldpalar commented May 12, 2017

I ended up put the original line from WP as below
case 'meta_value':
if ( ! empty( $primary_meta_query['type'] ) ) {
$orderby_clause = "meta_value";
$orderbyfields = $orderbyfields . ", CAST({$primary_meta_query['alias']}.meta_value AS {$sql_type}) as meta_value";
} else {
$orderbyfields = $orderbyfields . ", {$primary_meta_query['alias']}.meta_value";
$orderby_clause = "{$primary_meta_query['alias']}.meta_value"; //original line from WP
}
break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment