Plugin Directory

Changeset 3003610


Ignore:
Timestamp:
11/30/2023 08:04:40 AM (2 years ago)
Author:
belingo
Message:

fix sitemaps taxonomies and hide empty sitemaps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • belingogeo/trunk/includes/sitemaps.php

    r2995585 r3003610  
    2424        }
    2525    }
    26        
    27     belingoGeo_get_xml($urls);
    28     exit;
     26   
     27    if(is_array($urls) && count($urls) > 0) {
     28        belingoGeo_get_xml($urls);
     29        exit;
     30    }else{
     31        global $wp_query;
     32        $wp_query->set_404();
     33        status_header( 404 );
     34        nocache_headers();
     35    }
    2936   
    3037}
     
    151158            }
    152159            $taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ), 'objects' );
     160            $exclude_taxonomies = get_option('belingo_geo_exclude_taxonomies');
    153161            foreach($taxonomies as $taxonomy) {
    154                 if($taxonomy->public == 1 && $taxonomy->show_ui == 1) {
     162                if($taxonomy->public == 1 && $taxonomy->show_ui == 1 && !array_key_exists($taxonomy->name, $exclude_taxonomies)) {
    155163                    $url = [
    156164                        "loc" => get_site_url() . '/'.$city->get_slug().'_sitemap_tax_'.$taxonomy->name.'.xml',
     
    278286    $urls = [];
    279287
    280     $terms = get_terms(array(
    281         'taxonomy' => $taxonomy
    282     ));
    283     foreach ($terms as $term) {
    284         $loc = get_term_link($term->slug, $taxonomy);
    285         $current_city = belingoGeo_get_current_city();
    286         if($current_city) {
    287             $loc = belingogeo_remove_city_url($loc, $current_city->get_slug());
    288         }
    289         $loc = belingoGeo_append_city_url($loc, $city);
    290         $urls[] = [
    291             "loc" => $loc,
    292             "lastmod" => date('c',time())
    293         ];
     288    $exclude_taxonomies = get_option('belingo_geo_exclude_taxonomies');
     289
     290    if(!array_key_exists($taxonomy, $exclude_taxonomies)) {
     291
     292        $terms = get_terms(array(
     293            'taxonomy' => $taxonomy
     294        ));
     295        foreach ($terms as $term) {
     296            $loc = get_term_link($term->slug, $taxonomy);
     297            $current_city = belingoGeo_get_current_city();
     298            if($current_city) {
     299                $loc = belingogeo_remove_city_url($loc, $current_city->get_slug());
     300            }
     301            $loc = belingoGeo_append_city_url($loc, $city);
     302            $urls[] = [
     303                "loc" => $loc,
     304                "lastmod" => date('c',time())
     305            ];
     306        }
     307
    294308    }
    295309
Note: See TracChangeset for help on using the changeset viewer.