Created
April 16, 2018 16:26
-
-
Save frantisekz/f080b5b8c577df4601cd24820293b70a to your computer and use it in GitHub Desktop.
rh_research_calc_theses
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 | |
// $calculated_applicants = array('topic_id' => 'number_of_applicants'); | |
$args_theses=array( | |
# Set parameters, so the query will loop through all Theses | |
'post_type' => 'theses', | |
'post_status' => 'publish', | |
'posts_per_page' => -1, | |
'ignore_sticky_posts' => 1); | |
$theses_query = new WP_Query($args_theses); | |
if( $theses_query->have_posts() ) { | |
# Init the loop, one iteration per thesis | |
while ($theses_query->have_posts()) : $theses_query->the_post(); | |
# Fetch all metadata for thesis (we need id of linked Diploma Topic) | |
$terms_topics = wp_get_object_terms(get_the_ID(), 'diplomas'); | |
# Loop through all linked Topics with single Thesis (so, we should have one iteration only here) | |
foreach ($terms_topics as $terms_topic) { | |
# Prevent accessing out of array bounds | |
if (isset($calculated_applicants[$terms_topic->term_id])) { | |
$calculated_applicants[$terms_topic->term_id] = $calculated_applicants[$terms_topic->term_id] + 1; | |
} | |
else { | |
$calculated_applicants[$terms_topic->term_id] = 1; | |
} | |
} | |
endwhile; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment