Last active
June 14, 2016 15:37
-
-
Save epierpont/d21ea29e16af93218ac32148538efff7 to your computer and use it in GitHub Desktop.
WP - Custom tax query for NSP Advanced Post Types Order
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 | |
/* | |
I needed a way to override sort list query rules in the admin with my own custom tax queries. | |
So I created a list using the default query rules, saved the unique reorder sort ID to a page as a custom field | |
and used it to alter and assign the new tax query. | |
NSP Advanced Post Types Order Plugin - http://www.nsp-code.com/advanced-post-types-order-api/sample-usage/ | |
*/ | |
add_filter( 'apto_interface_query_args', 'linkReorderLists', 10, 2 ); | |
function linkReorderLists( $args, $sort_view_id ) { | |
// get reorder sort ID that is being passed | |
$sortID = $args['sort_id']; | |
// find page where I'm saving unique reorder sort ID as custom field | |
$reorderCarousels = new WP_Query( array( | |
'post_type' => 'page', | |
'meta_key' => 'carousel_sort_id', | |
'meta_value' => $sortID ) | |
); | |
// run through custom tax query, this will now link to $sortID | |
if ( $reorderCarousels->have_posts() ) { | |
while ( $reorderCarousels->have_posts() ) { | |
$reorderCarousels->the_post(); | |
$args['tax_query'] = array( | |
'relation' => 'OR', | |
array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'include_children' => false, | |
'terms' => array( 'example-cat-1', 'example-cat-2' ), | |
), | |
array( | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => array( 'example-cat-3', 'example-cat-4' ), | |
), | |
)); | |
} | |
} | |
wp_reset_postdata(); | |
return $args; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment