Skip to content

Instantly share code, notes, and snippets.

@deltamualpha
Last active December 17, 2015 16:30
Show Gist options
  • Save deltamualpha/5639611 to your computer and use it in GitHub Desktop.
Save deltamualpha/5639611 to your computer and use it in GitHub Desktop.
A way to run a number of different tag queries in wordpress and then sort the results, putting the queries that match the most tags at the top.
$queries_array = {$query_1, $query_2, $query_n};
$merged_array = array_reduce($queries_array, array_merge);
$uniques = array();
$counter = array();
foreach ( $merged_array as $current ) {
$counter[current->id] += $counter[current->id];
$uniques[current->id] = $current; // pulls out unique only
}
arsort($counter);
foreach ( $counter as $id => $count) {
$uniques[$id];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment