• Resolved jerryxcoke

    (@jerryxcoke)


    Hi,

    I try to use ‘wpseo_exclude_from_sitemap_by_term_ids’ hook, but after the implementation, The taxonomy specific sitemap still contains bad links which have excluded term taxonomy ids.

    the code :

    function sitemap_exclude_terms( $terms ) {
        return [ 33,34 ];
    }
    
    add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', 'sitemap_exclude_terms', 10, 1 );

    I tried to turn off and on the sitemap feature, I purged my cache multiply times, but the links still there.

    What did I miss?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support devnihil

    (@devnihil)

    @jerryxcoke Unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Thread Starter jerryxcoke

    (@jerryxcoke)

    @devnihil, Thanks for the quick reply. I understand that custom code is not supported.

    Is there any developer forum or guideline for these issues?
    The hook is documented here: https://developer.yoast.com/features/xml-sitemaps/api/, but this is all that I found. I don’t want to open github ticket beacuse I do not have any proof that This is a bug.

    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    We have just tested the relevant code snippet provided here that usage the wpseo_exclude_from_sitemap_by_term_ids filter and can confirm that it’s working fine from our end.

    So, if that’s something not working for you, please make sure that you used the correct category ID within the array. If that still doesn’t work for you, please try resetting the Indexables tables and migrations by following the steps given below to see whether this works for you:

    • Install and activate Yoast Test Helper plugin;
    • Go to Tools → Yoast Test → Yoast SEO → Reset indexables tables & migrations options to reset it;
    • Run SEO data optimization from the SEO → Tools page.

    Let us know whether the issue persists after performing the above steps.

    Sa?a

    (@stodorovic)

    Reset indexables can’t help (sitemaps still don’t use indexables). It looks that you didn’t use correct term IDs, but I can’t be sure from your comments.

    There are two “taxonomy ids” – https://codex.www.ads-software.com/WordPress_Taxonomy:

    • term_id is the ID of a term in the terms table.
    • taxonomy designates the taxonomy in which the term resides. The default taxonomies are category, link_category, and post_tag.
    • term_taxonomy_id is a unique ID for the term+taxonomy pair.

    You can see more details (how MySQL tables are linked) – https://code.tutsplus.com/tutorials/understanding-and-working-with-taxonomies-and-terms-in-wordpress–cms-21051

    The filter wpseo_exclude_from_sitemap_by_term_ids uses term_id ( not term_taxonomy_id ) and it could be a reason why it doesn’t work. You can see it into source code:

    /**
     * Filter: 'wpseo_exclude_from_sitemap_by_term_ids' - Allow excluding terms by ID.
     *
     * @api array $terms_to_exclude The terms to exclude.
     */
    $terms_to_exclude = apply_filters( 'wpseo_exclude_from_sitemap_by_term_ids', [] );
    
    foreach ( $terms as $term ) {
    
        if ( in_array( $term->term_id, $terms_to_exclude, true ) ) {
            continue;
        }
    
    Thread Starter jerryxcoke

    (@jerryxcoke)

    Oh that is a great explanation @stodorovic . I really missunderstood the terminology of terms and I use term_taxonomy_id instead of term_id. Totally my fault.

    @mazedulislamkhan also thanks for quick debug check.

    Thanks all

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘sitemap did not updated after excluded some term ids’ is closed to new replies.