WordPress.org

Ready to get started?Download WordPress

Forums

  1. Lumpysimon
    Member
    Posted 2 years ago #

    Hi

    Is it possible to exclude posts/pages from the sitemap by ID?

    I've looked through the instructions on your website but can't see an obvious way, apart from making new modules that exclude IDs in the SQL query in the generate_data function and using these instead of the default modules - is that the best way to do it?

    Thanks
    Simon

  2. Khang Minh
    Member
    Plugin Author

    Posted 2 years ago #

    HI again Simon :)

    You are right, that's currently, and generally the best way to do it, because for such thing I really don't want to rely on the database. Anyway, in the next major version, which is expected to be released this week, I will add a hook to the default post and page module so that you can simply filter the WHERE part of the query, like ID NOT IN (1,2,3,4). Is that OK for you?

  3. Lumpysimon
    Member
    Posted 2 years ago #

    That's great - a filter hook sounds like the perfect answer.

    Cheers!
    Simon

  4. Lumpysimon
    Member
    Posted 2 years ago #

    i'm having problems getting this to work for page exclusion using the new bwp_gxs_post_where filter. here's my code:

    function sitemap_where( $post_type ) {
    
    	switch ( $post_type ) {
    		case 'page' :
    			return ' AND wposts.ID NOT IN (128,187,5339) ';
    		break;
    	}
    
    	return '';
    
    }

    but those pages are still showing in the sitemap (i deleted the sitemap cache so they are freshly rebuilt).

    thanks
    simon

  5. Khang Minh
    Member
    Plugin Author

    Posted 2 years ago #

    Simon,

    I've sent you an email with patch and instructions, hope it helps :).

  6. Lumpysimon
    Member
    Posted 2 years ago #

    Afraid it's not working with the patch, the excluded pages are still in the sitemap...

  7. Khang Minh
    Member
    Plugin Author

    Posted 2 years ago #

    Simon,

    Sorry for that, I have a typo in my example (fixed, thanks to you!), you should replace your filter with this:

    add_filter('bwp_gxs_post_where', 'sitemap_where', 10, 2);
    
    function sitemap_where( $query, $post_type ) {
    
    	switch ( $post_type ) {
    		case 'page' :
    			return ' AND wposts.ID NOT IN (128,187,5339) ';
    		break;
    	}
    
    	return '';
    
    }
    

    I'm pretty sure it will work now :).

  8. Lumpysimon
    Member
    Posted 2 years ago #

    that's perfect thanks, works a treat now.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic