There's a wordpress plugin that i'm attempting to adapt for my meta_tags to be used with WordPress. It's known as Groups by Title by

Things I am attempting to achieve is really a nested sort. I've three meta_secrets. A variety-no, release-month, and release-year. I must sort posts inside their category by release-year (asc), release-month (asc), then selection-no (asc). For instance: 1955 10 selection-no-1, 1956 10 selection-no-2, 1956 10 selection-no-5, and so forth.

I've modified the code, however, it only sorts through the last meta_key listed, by release-year.

This is actually the code.


function sort_categories_by_title($x) {
if(is_category()) {
    $x->query_vars['orderby'] = 'meta_value';
    $x->query_vars['meta_key'] = 'selection-no';
    $x->query_vars['meta_key'] = 'release-month';
    $x->query_vars['meta_key'] = 'release-year';
    $x->query_vars['order'] = 'asc';

Any help could be greatly appreciated. Thanks.

Take a look at usort. You give you a comparison function which could look inside the items and select things to order by.

Inside your example, any time you do $x->query_vars['meta_key'] you overwrite the prior value, so you are only adding the final meta_key like a selection option.

In addition WordPress only supports tugging with a single meta_key/meta_value comparison. To obtain the more complicated comparison that you are after you ought to be blocking on posts_where_paged to include in additional evaluations and posts_orderby to create an order by clause that you'll require. You will need a fundamental understanding of raw SQL query writing to do this.

You may consider restructuring your computer data too and putting the discharge-date in a real date format and taking advantage of typecasting to accept string format from the meta_value and cast it as being to start dating ? area to then do proper date based sorting procedures onto it.