• WooCommerce sites use a post type called “shop_order” to hold orders, naturally we don’t want these showing up in the sitemap but we definitely do want “products” to appear.

    Attached is a patch that adds an “Exclude Post Type” field to the configuration screen and allows a user to supply a comma-separated list of post types that should be excluded.

    Hope this is helpful!

    diff --git a/wp-content/plugins/wp-realtime-sitemap/wp-realtime-sitemap.php b/wp-content/plugins/wp-realtime-sitemap/wp-realtime-sitemap.php
    index 3cc3127..d0c461c 100644
    --- a/wp-content/plugins/wp-realtime-sitemap/wp-realtime-sitemap.php
    +++ b/wp-content/plugins/wp-realtime-sitemap/wp-realtime-sitemap.php
    @@ -191,6 +191,7 @@ if (!class_exists('WPRealtimeSitemap')) {
     			add_settings_field('post_orderby', __('Order By', 'wp-realtime-sitemap'), array($this, '_formSelectInput'), __FILE__, 'post_settings', array('dbfield' => 'post_orderby', 'section' => 'post'));
     			add_settings_field('post_order', __('Order', 'wp-realtime-sitemap'), array($this, '_formSelectInput'), __FILE__, 'post_settings', array('dbfield' => 'post_order', 'section' => 'post'));
     			add_settings_field('post_exclude', __('Exclude IDs', 'wp-realtime-sitemap'), array($this, '_formTextInput'), __FILE__, 'post_settings', array('dbfield' => 'post_exclude', 'section' => 'post'));
    +			add_settings_field('post_type_exclude', __('Exclude Post Types', 'wp-realtime-sitemap'), array($this, '_formTextInput'), __FILE__, 'post_settings', array('dbfield' => 'post_type_exclude', 'section' => 'post'));
     			add_settings_field('post_show_date', __('Display Date', 'wp-realtime-sitemap'), array($this, '_formSelectInput'), __FILE__, 'post_settings', array('dbfield' => 'post_show_date', 'section' => 'post'));
     			add_settings_field('post_numberposts', __('Limit', 'wp-realtime-sitemap'), array($this, '_formTextInput'), __FILE__, 'post_settings', array('dbfield' => 'post_numberposts', 'section' => 'post'));
     			add_settings_field('post_show_categories', __('Display Categories', 'wp-realtime-sitemap'), array($this, '_formSelectInput'), __FILE__, 'post_settings', array('dbfield' => 'post_show_categories', 'section' => 'post'));
    @@ -678,6 +679,10 @@ if (!class_exists('WPRealtimeSitemap')) {
     					$infotext = __('Comma separated list of IDs.', 'wp-realtime-sitemap');
     					break;
    
    +				case 'post_type_exclude':
    +  					$infotext = __('Comma separated list of post types.', 'wp-realtime-sitemap');
    +  					break;
    +
     				case 'post_show_date':
     					$infotext = '';
     					break;
    @@ -938,6 +943,11 @@ if (!class_exists('WPRealtimeSitemap')) {
     									'default' => '',
     									'errormsg' => __('Post Settings', 'wp-realtime-sitemap') . ' > ' . __('Exclude', 'wp-realtime-sitemap') . ': ' . __('This must be comment seperated list of IDs for it to be valid, please try again.', 'wp-realtime-sitemap'),
     								),
    +				'post_type_exclude'			=> array(
    +									'valid' => array(),
    +									'default' => '',
    +									'errormsg' => __('Post Settings', 'wp-realtime-sitemap') . ' > ' . __('Exclude', 'wp-realtime-sitemap') . ': ' . __('This must be comment seperated list of IDs for it to be valid, please try again.', 'wp-realtime-sitemap'),
    +								),
     				'post_show_date'		=> array(
     									'valid' => array_keys($this->_formValidDefaults(array('dbfield' => 'post_show_date'))),
     									'default' => '',
    @@ -1194,6 +1204,8 @@ if (!class_exists('WPRealtimeSitemap')) {
     			}
    
     			$plugin_wp_realtime_sitemap_settings['post_exclude'] = $inputs['post_exclude'];
    +
    +			$plugin_wp_realtime_sitemap_settings['post_type_exclude'] = $inputs['post_type_exclude'];
    
     			if(!in_array($inputs['post_show_date'], $validInputs['post_show_date']['valid'])) {
     				$plugin_wp_realtime_sitemap_settings['post_show_date'] = $validInputs['post_show_date']['default'];
    @@ -1665,6 +1677,11 @@ if (!class_exists('WPRealtimeSitemap')) {
     					$post_types = get_post_types(array('public' => true, '_builtin' => false), 'objects');
    
     					foreach ($post_types as $post_type) {
    +					  // Exclude specific post types
    +					  if(in_array($post_type->name, explode(',', $all_options['post_type_exclude']))) {
    +					    continue;
    +					  }
    +
     						$custom_post_type_posts = '';
    
     						// Set options for post query

    http://wordpress.org/extend/plugins/wp-realtime-sitemap/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rincewind

    (@rincewind)

    ah I see ok, thank you I will implement this soon thanks very much for the patch.

    Hi there,

    I want only to show ONE custum post type, but it show’s all.
    I don’t manage to get one excluded. Is this patch usefull for it?

    What do you mean with 678,6, 679,10?

    Willem

    Thread Starter garethsprice

    (@garethsprice)

    @willem – this patch only excludes specific post types. To show one post type only, enter all the other post types into the exclude list.

    The 678,6-679,10 numbers are because this is a patch for the existing plugin that you will need to apply using GNU diff from the command line. The numbers indicate which line numbers have been modified in the file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WP Realtime Sitemap] Patch to add option to exclude custom post types’ is closed to new replies.