Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Matt,

    Thanks!

    About the filter:
    I will add the requested filters in the next update. I’ll keep you updated on how they will work.

    Alternative:
    If you don’t wish to include a page in the sitemap, I believe you might also want to exclude it from Search Engine Result Pages?
    If this is the case, simply check the “NoIndex” box on the SEO Settings within the page edit screen. This will effectively remove the page from the sitemap as well.

    About the query:
    Thank you very much for the suggestion as well, any input is greatly appreciated. I took your suggestion to the test below:

    About the combining of the fetch into 1 query:
    You’re right! Alas, this isn’t possible with the get_posts() function considering the possible post amount filters (4 different filters).
    Also, doing so will make the sitemap links generation much harder. As we have to check in each loop what kind of post type it is. With thousands of posts, this is quite hefty. Reading more down the line of the code, you see I treat Pages and Posts/CPT quite differently.

    About the how-to-combine SQL link:
    Great stuff :D. I love to learn!
    I do have to note that this plugin (like many others) is dependent on the WordPress core, and rewriting the query function is a hefty and very prone be a buggy task. Especially if you consider it to be more than 1200 lines of code long, which can be changed at any future Core update. Including consideration of MariaDB, SQL Server, MySQLi, PostgreSQL, etc.:
    WP_Query::get_posts()

    All with all, I took the liberty of speed-testing the queries, results may vary:

    Pages fetch: 0.0007419586181640625 seconds
    Posts fetch: 0.000771045684814453125 seconds
    CPT calculation (no CPT registered): 1.1920928955078125-5 seconds
    CPT calculation + fetch (WooCommerce + bbPress + AnsPress): 0.0058460235595703125 seconds

    I think it’s quite negligible :), what do you think?

    I hope this clears things up, I’ll keep you posted!

    Thread Starter Matt Gibbs

    (@mgibbs189)

    Hey Sybre,

    It’s entirely possible to use a single query when using WP_Query. All we need is to use the posts_orderby filter. There is no extra overhead to check post_type, since it’s already included with both get_posts() and WP_Query.

    I’ll try to submit a PR with these proposed changes.

    FYI – get_posts() uses WP_Query behind the scenes.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Matt,

    Yea, I noticed that 😀 I never took the time to look through the whole get_posts code and I believe the Github link I sent covers that area :O.

    Let me know if I’ve set up the git wrong, I never truly have used it before The SEO Framework.
    Keep me updated if everything goes as planned, I’ll take a look at the PR when ready and will test it :). All help is truly appreciated!

    I finally was able again to free some of my time towards this plugin, so for now I have about 27 changes (of which are 7 bugfixes) I need to write before heading over onto optimizing.

    Please also be aware that the sitemap is cached through a transient, this makes optimizing it having a lower priority on my list, next to that it’s already very optimized as it handles up to 2000 posts with only 5MB extra server RAM usage (before it was 15MB with 2000 posts). I must be very wary about that because not everyone ups their PHP RAM availability. Holding onto my motto: It should just work, always.

    Using the following constant, you can see the Site/System RAM usage estimates and the Sitemap generation time at the bottom of the sitemap:

    define( 'THE_SEO_FRAMEWORK_DEBUG', true );

    I hope this helps 🙂

    Thanks and have a great day!

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Matt!

    The filters have been included in 2.5.2 (almost released), they are the following:

    the_seo_framework_sitemap_exclude_post_ids
    the_seo_framework_sitemap_exclude_page_ids
    the_seo_framework_sitemap_exclude_cpt_ids

    Example usage:

    add_filter( 'the_seo_framework_sitemap_exclude_cpt_ids', 'my_exclude_cpt_ids' );
    function my_exclude_cpt_ids() {
    	$ids = 2; // Either a single integer
    	$ids = array( 2, 3, 6, 10 ); // Or an array with integers
    
    	return $ids;
    }

    I hope this helps 🙂

    Thanks and have a great day!

    Thread Starter Matt Gibbs

    (@mgibbs189)

    Sybre,

    Thanks for your effort! This still looks like overkill though.

    Again, it’s possible to (easily) modify the sitemap so the entire thing uses 1 query. That would also allow for a single the_seo_framework_sitemap_exclude_ids filter, instead of the 3 ones you proposed.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Matt,

    Anytime!

    Now I think about it, you’re right, it is! Thanks for the suggestion :).
    I’ll convert it to a single filter, it will work as suggested above. To be correct, here it is again with the updated filter name:

    the_seo_framework_sitemap_exclude_ids

    Usage:

    add_filter( 'the_seo_framework_sitemap_exclude_ids', 'my_sitemap_exclude_ids' );
    function my_sitemap_exclude_ids() {
    	$ids = 2; // Either a single integer
    	$ids = array( 2, 3, 6, 10 ); // Or an array with integers
    
    	return $ids;
    }

    Reworking the query as suggested will of course be considered in a future update.

    Thanks and have a wonderful day!

    Thread Starter Matt Gibbs

    (@mgibbs189)

    Thanks, great work BTW!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Filter request: exclude specific post IDs from sitemap’ is closed to new replies.