Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $allposts = get_posts('post_type=post&numberposts=100'); //get a lot of recent posts
- $cats = array(); $cat = array(); //initialize arrays
- foreach($allposts as $allpost) {
- $postcats = get_the_category($allpost->ID); //get all post's categories
- foreach($postcats as $ca) { $cat[] = $ca->term_id; } $postcats = $cat; $cat = array(); //this uses less queries than wp_get_post_categories()
- $cats = array_merge($cats,$postcats);
- $cats = array_unique($cats); } //only keep unique category IDs
- $allcats = get_categories(); //get all categories of the site, in case tha latest posts are not covering all categories/
- foreach($allcats as $allcat) { $sitecats[] = $allcat->term_id; }; //get the category IDs
- $cats = array_merge($cats, $sitecats); //add to the already collected categories
- $cats = array_unique($cats); //only keep unique category IDs
- $section_cats = array(1,23,48,128,9,19,67); //allowed categories for the automated section
- $cats = array_intersect( $cats, $section_cats );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement