return $query_args;
}
function custom_order($orderby) {
global $wpdb;
return $wpdb->postmeta.'.meta_value, mt1.meta_value, post_date ASC';
}
I'm not sure what the 99, 3 is for and this doesn't work - give error on page:
"Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_custom_fields_to_view_query' not found or invalid function name in /var/www/wordpress/hqinstruction/wp-includes/class-wp-hook.php on line 287"
It should be noted that even through this is not something that is supported by our Toolset team as sorting by multiple custom fields is not supported.
However based on your error I see where you are writing the function name incorrectly. It should be add_custom_fields_to_view_query and not add_custom_fiels_to_view_query
function custom_order($orderby) {
global $wpdb;
return $wpdb->postmeta.'.meta_value, mt1.meta_value, post_title ASC';
}
Additionally you know that our views allows for this out the box. You are able to sort by a custom field and a secondary sorting for the post title, you don't need to write a custom code for this. I was under the impression that both fields were custom fields. Given that they aren't you can do this through the sorting option for our view.
Unfortunately I wouldn't be able to modify the code to work for this scenario as the custom coding is out of our support scope. This is because this code is written to work with 2 custom fields so it will need some modifications or rather a new custom code in order to get this sorting to work.
I did check in the forms to see how we can get get some reference code and this may help.
Please let me know if this code itself works. If it doesn't then I would recommend getting in touch with a developer in order to get further assistance with this.
This does not work - result show but aren't sorting by the year desc.
Would you like admin access to the site?
Meanwhile the client has decided they want secondary ordering by the custom grades-radio field not the year field. That shouldn't change this request much except that I'll need to order the results by the "value to show" rather than "custom field content" because they need to go in the order K-2, 3-5, 6-8.
As mentioned previously this would be something out of the scope of our support forum and given that we weren't able to resolve it with a few changes, this would mean some additional steps are needed. Whenever I checked out forums customers are usually asking for sorting with 2 custom fields.
As recommended before it would be best to get a developer involved to modify the code in order for it to display the correct sorting. The most I can do is to look for syntactical errors.
And this code is almost working. The issue is I can't seem to move post_title to be the first thing to sort because then it shows an error on the page. This does not work: return $wpdb->postmeta.'.post_title ASC, meta_value DESC';
function custom_order_curricula($orderby) {
global $wpdb;
return $wpdb->postmeta.'.meta_value ASC, post_title ASC';
}
changing the order shows this error:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DESC, post_modified DESC' at line 3]
SELECT wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND wp_posts.ID NOT IN (19) AND ( wp_postmeta.meta_key = 'wpcf-grades-radio' ) AND wp_posts.post_type = 'curricula' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) GROUP BY wp_posts.ID ORDER BY wp_postmetapost_title ASC, .meta_value DESC, post_modified DESC