Add to functions.php page
Excludes category 74 from the wordpress blog page, then adds all in cat 1 and 74 to the sitemap.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
// Exclude 'locations' category from the blog page function exclude_category_from_blog($query) { if ($query->is_home()) { $query->set('cat', '-74'); // Excludes posts from category ID 74 } return $query; } add_filter('pre_get_posts', 'exclude_category_from_blog'); // Manually add 'locations' and 'General' category posts to the sitemap function add_specific_categories_to_sitemap($args) { if (!isset($args['tax_query'])) { $args['tax_query'] = array(); } // Prepare the tax query for both 'locations' and 'General' categories $locations_general_tax_query = array( 'relation' => 'OR', array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => 74, // ID of the 'locations' category ), array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => 1, // ID of the 'General' category ), ); // If there is an existing tax query, merge it with the new one if (!empty($args['tax_query'])) { $args['tax_query'] = array_merge($args['tax_query'], $locations_general_tax_query); } else { $args['tax_query'] = $locations_general_tax_query; } return $args; } add_filter('wp_sitemaps_posts_query_args', 'add_specific_categories_to_sitemap'); |