| @@ 1564-1646 (lines=83) @@ | ||
| 1561 | /** |
|
| 1562 | * @ticket 34996 |
|
| 1563 | */ |
|
| 1564 | public function test_orderby_meta_value_with_meta_key() |
|
| 1565 | { |
|
| 1566 | register_taxonomy('wptests_tax', 'post'); |
|
| 1567 | $terms = self::factory()->term->create_many(3, array( 'taxonomy' => 'wptests_tax' )); |
|
| 1568 | add_term_meta($terms[0], 'foo', 'bar'); |
|
| 1569 | add_term_meta($terms[0], 'fee', 'zzz'); |
|
| 1570 | add_term_meta($terms[0], 'faa', 'jjj'); |
|
| 1571 | add_term_meta($terms[1], 'foo', 'bar'); |
|
| 1572 | add_term_meta($terms[1], 'fee', 'aaa'); |
|
| 1573 | add_term_meta($terms[1], 'faa', 'aaa'); |
|
| 1574 | add_term_meta($terms[2], 'foo', 'bar'); |
|
| 1575 | add_term_meta($terms[2], 'fee', 'jjj'); |
|
| 1576 | add_term_meta($terms[2], 'faa', 'zzz'); |
|
| 1577 | ||
| 1578 | $found = get_terms( |
|
| 1579 | 'wptests_tax', array( |
|
| 1580 | 'hide_empty' => false, |
|
| 1581 | 'meta_key' => 'fee', |
|
| 1582 | 'orderby' => 'meta_value', |
|
| 1583 | 'order' => 'ASC', |
|
| 1584 | 'fields' => 'ids', |
|
| 1585 | ) |
|
| 1586 | ); |
|
| 1587 | ||
| 1588 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1589 | ||
| 1590 | $found = get_terms( |
|
| 1591 | 'wptests_tax', array( |
|
| 1592 | 'hide_empty' => false, |
|
| 1593 | 'meta_query' => array( |
|
| 1594 | array( |
|
| 1595 | 'key' => 'foo', |
|
| 1596 | 'compare' => 'EXISTS', |
|
| 1597 | ), |
|
| 1598 | ), |
|
| 1599 | 'meta_key' => 'fee', |
|
| 1600 | 'orderby' => 'meta_value', |
|
| 1601 | 'order' => 'ASC', |
|
| 1602 | 'fields' => 'ids', |
|
| 1603 | ) |
|
| 1604 | ); |
|
| 1605 | ||
| 1606 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1607 | ||
| 1608 | // Matches the first meta query clause. |
|
| 1609 | $found = get_terms( |
|
| 1610 | 'wptests_tax', array( |
|
| 1611 | 'hide_empty' => false, |
|
| 1612 | 'meta_query' => array( |
|
| 1613 | 'relation' => 'AND', |
|
| 1614 | array( |
|
| 1615 | 'key' => 'foo', |
|
| 1616 | 'compare' => 'EXISTS', |
|
| 1617 | ), |
|
| 1618 | array( |
|
| 1619 | 'key' => 'fee', |
|
| 1620 | 'compare' => 'EXISTS', |
|
| 1621 | ), |
|
| 1622 | ), |
|
| 1623 | 'meta_key' => 'fee', |
|
| 1624 | 'orderby' => 'meta_value', |
|
| 1625 | 'order' => 'ASC', |
|
| 1626 | 'fields' => 'ids', |
|
| 1627 | ) |
|
| 1628 | ); |
|
| 1629 | ||
| 1630 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1631 | ||
| 1632 | // Matches the meta query clause corresponding to the 'meta_key' param. |
|
| 1633 | $found = get_terms( |
|
| 1634 | 'wptests_tax', array( |
|
| 1635 | 'hide_empty' => false, |
|
| 1636 | 'meta_query' => array( |
|
| 1637 | 'relation' => 'AND', |
|
| 1638 | array( |
|
| 1639 | 'key' => 'foo', |
|
| 1640 | 'compare' => 'EXISTS', |
|
| 1641 | ), |
|
| 1642 | array( |
|
| 1643 | 'key' => 'fee', |
|
| 1644 | 'compare' => 'EXISTS', |
|
| 1645 | ), |
|
| 1646 | ), |
|
| 1647 | 'meta_key' => 'faa', |
|
| 1648 | 'orderby' => 'meta_value', |
|
| 1649 | 'order' => 'ASC', |
|
| @@ 1660-1740 (lines=81) @@ | ||
| 1657 | /** |
|
| 1658 | * @ticket 34996 |
|
| 1659 | */ |
|
| 1660 | public function test_orderby_meta_value_num_with_meta_key() |
|
| 1661 | { |
|
| 1662 | register_taxonomy('wptests_tax', 'post'); |
|
| 1663 | $terms = self::factory()->term->create_many(3, array( 'taxonomy' => 'wptests_tax' )); |
|
| 1664 | add_term_meta($terms[0], 'foo', 'bar'); |
|
| 1665 | add_term_meta($terms[0], 'fee', '999'); |
|
| 1666 | add_term_meta($terms[0], 'faa', '555'); |
|
| 1667 | add_term_meta($terms[1], 'foo', 'bar'); |
|
| 1668 | add_term_meta($terms[1], 'fee', '111'); |
|
| 1669 | add_term_meta($terms[1], 'faa', '111'); |
|
| 1670 | add_term_meta($terms[2], 'foo', 'bar'); |
|
| 1671 | add_term_meta($terms[2], 'fee', '555'); |
|
| 1672 | add_term_meta($terms[2], 'faa', '999'); |
|
| 1673 | ||
| 1674 | $found = get_terms( |
|
| 1675 | 'wptests_tax', array( |
|
| 1676 | 'hide_empty' => false, |
|
| 1677 | 'meta_key' => 'fee', |
|
| 1678 | 'orderby' => 'meta_value', |
|
| 1679 | 'order' => 'ASC', |
|
| 1680 | 'fields' => 'ids', |
|
| 1681 | ) |
|
| 1682 | ); |
|
| 1683 | ||
| 1684 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1685 | ||
| 1686 | $found = get_terms( |
|
| 1687 | 'wptests_tax', array( |
|
| 1688 | 'hide_empty' => false, |
|
| 1689 | 'meta_query' => array( |
|
| 1690 | array( |
|
| 1691 | 'key' => 'foo', |
|
| 1692 | 'compare' => 'EXISTS', |
|
| 1693 | ), |
|
| 1694 | ), |
|
| 1695 | 'meta_key' => 'fee', |
|
| 1696 | 'orderby' => 'meta_value', |
|
| 1697 | 'order' => 'ASC', |
|
| 1698 | 'fields' => 'ids', |
|
| 1699 | ) |
|
| 1700 | ); |
|
| 1701 | ||
| 1702 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1703 | ||
| 1704 | $found = get_terms( |
|
| 1705 | 'wptests_tax', array( |
|
| 1706 | 'hide_empty' => false, |
|
| 1707 | 'meta_query' => array( |
|
| 1708 | 'relation' => 'AND', |
|
| 1709 | array( |
|
| 1710 | 'key' => 'foo', |
|
| 1711 | 'compare' => 'EXISTS', |
|
| 1712 | ), |
|
| 1713 | array( |
|
| 1714 | 'key' => 'fee', |
|
| 1715 | 'compare' => 'EXISTS', |
|
| 1716 | ), |
|
| 1717 | ), |
|
| 1718 | 'meta_key' => 'fee', |
|
| 1719 | 'orderby' => 'meta_value', |
|
| 1720 | 'order' => 'ASC', |
|
| 1721 | 'fields' => 'ids', |
|
| 1722 | ) |
|
| 1723 | ); |
|
| 1724 | ||
| 1725 | $this->assertEqualSets(array( $terms[1], $terms[2], $terms[0] ), $found); |
|
| 1726 | ||
| 1727 | $found = get_terms( |
|
| 1728 | 'wptests_tax', array( |
|
| 1729 | 'hide_empty' => false, |
|
| 1730 | 'meta_query' => array( |
|
| 1731 | 'relation' => 'AND', |
|
| 1732 | array( |
|
| 1733 | 'key' => 'foo', |
|
| 1734 | 'compare' => 'EXISTS', |
|
| 1735 | ), |
|
| 1736 | array( |
|
| 1737 | 'key' => 'fee', |
|
| 1738 | 'compare' => 'EXISTS', |
|
| 1739 | ), |
|
| 1740 | ), |
|
| 1741 | 'meta_key' => 'faa', |
|
| 1742 | 'orderby' => 'meta_value', |
|
| 1743 | 'order' => 'ASC', |
|