Last active
July 18, 2017 09:20
-
-
Save vovadocent/1a62e320ddfb77955365ea50a5eb7b15 to your computer and use it in GitHub Desktop.
WP order post type by taxonomy name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$oargs = array('orderby' => 'post__in', 'post__in' => get_order_tax_ids('events', 'region')); | |
//$args = array_merge($args, $oargs); | |
function get_order_tax_ids($post_type, $taxonomy) { | |
global $wpdb; | |
$ids = []; | |
$sql = "SELECT p.ID FROM $wpdb->posts p | |
JOIN $wpdb->term_relationships tr ON (tr.object_id = p.ID) | |
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND taxonomy = '$taxonomy') | |
JOIN $wpdb->terms t ON (t.term_id = tt.term_id) | |
WHERE post_status = 'publish' AND post_type = '$post_type' ORDER BY t.name ASC"; | |
$ids = $wpdb->get_col($sql); | |
return $ids; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment