Created
June 30, 2020 14:32
-
-
Save waynep16/de3705bd32dc40067f10e4f14502d60a to your computer and use it in GitHub Desktop.
Output Products based on team selected taxonomy
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
// Loop woo products by a teams chosen sector ACF field | |
function ics_sector_reports() { | |
// Get team ID for current user | |
$teams = wc_memberships_for_teams_get_teams( $user_id ); | |
if ( ! empty( $teams ) ) { | |
foreach ( $teams as $team ) { | |
$team_id = $team->get_id();} | |
// Get a teams sectorselection by team ID | |
$team_sectors = get_field( 'team_sectors' , $team_id); | |
// Create array of sector IDs to use in post query argument | |
if ( $team_sectors ) { | |
$arr = []; | |
foreach($team_sectors as $term){ | |
$arr[] = $term->term_id; | |
} | |
} | |
else | |
{ | |
$arr[] = ''; | |
} | |
return array( | |
'post_type' => 'product', | |
'posts_per_page' => 4, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'term_id', | |
// Get only items from Reports Woo Category | |
'terms' => array( 164 ), | |
'posts_per_page' => '1', | |
), | |
array( | |
// Restrict loop to only the ones we want based taxonomy | |
'taxonomy' => 'resourceindustry', | |
'field' => 'term_id', | |
'terms' => $arr, | |
'posts_per_page' => '1', | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment