[wp-trac] [WordPress Trac] #34996: Ordering taxonomies by term meta
WordPress Trac
noreply at wordpress.org
Sat Dec 12 17:43:08 UTC 2015
#34996: Ordering taxonomies by term meta
-------------------------------------------------+-------------------------
Reporter: eherman24 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future
Component: Taxonomy | Release
Severity: normal | Version: 4.4
Keywords: good-first-bug has-patch needs- | Resolution:
testing | Focuses:
-------------------------------------------------+-------------------------
Changes (by eherman24):
* keywords: needs-patch good-first-bug => good-first-bug has-patch needs-
testing
Comment:
I took a stab at an initial patch for this ticket. I'm no SQL wizard, but
it should be a solid starting point.
In my initial testing, using the above tax_position key (integers), the
following cases returned in proper format:
{{{
$terms = get_terms( 'taxonomy', array(
'hide_empty' => false,
'meta_query' => array(
'position_clause' => array(
'key' => 'tax_position',
'value' => 0,
'compare' => '>='
),
),
'orderby' => 'position_clause',
) );
}}}
and
{{{
$terms = get_terms( 'taxonomy', array(
'hide_empty' => false,
'meta_query' => array(
'position_clause' => array(
'key' => 'tax_position',
'value' => 0,
'compare' => '>='
),
),
'orderby' => 'meta_value_num',
) );
}}}
I then altered the data stored in the tax_position term meta to a string
instead of an integer (A,B,C etc.) and altered the query to test, and the
following returned true:
{{{
$terms = get_terms( 'taxonomy', array(
'hide_empty' => false,
'meta_query' => array(
'position_clause' => array(
'key' => 'tax_position',
'value' => 0,
'compare' => '>='
),
),
'orderby' => 'meta_value',
) );
}}}
I was able to sort in both 'ASC' and 'DESC' order (using `'order' =>
'ASC'` etc) successfully.
I'm sure some further, thorough testing will need to be done - so
additional feedback is invited.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34996#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list