• Resolved Simon Blackbourn

    (@lumpysimon)


    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Khang Minh

    (@oddoneout)

    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?

    Thread Starter Simon Blackbourn

    (@lumpysimon)

    That’s great – a filter hook sounds like the perfect answer.

    Cheers!
    Simon

    Thread Starter Simon Blackbourn

    (@lumpysimon)

    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

    Plugin Author Khang Minh

    (@oddoneout)

    Simon,

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

    Thread Starter Simon Blackbourn

    (@lumpysimon)

    Afraid it’s not working with the patch, the excluded pages are still in the sitemap…

    Plugin Author Khang Minh

    (@oddoneout)

    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 :).

    Thread Starter Simon Blackbourn

    (@lumpysimon)

    that’s perfect thanks, works a treat now.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Excluding posts/pages by ID’ is closed to new replies.