Where is the hook for : posts_to_exclude ?

  • Hi Rankmath SuperTeam !
    I’m wondering where is your hook for : posts_to_exclude

    A hook to which an id is transmitted to like in your admin settings ?
    Thanks in advance !

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can use the following filter to exclude posts from the sitemap:

    /**
     * Filter decision if post type is excluded from the XML sitemap.
     *
     * @param bool   $exclude Default false.
     * @param string $type    Post type name.
     */
    add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
    	return $exclude;
    }, 10, 2 );

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi, tx for your reply but,
    in fact i dont want to exclude post_type but post by ID like in your admin settings : https://zupimages.net/up/19/47/zqts.png

    the function you use in your plugin is :
    (in \seo-by-rank-math\includes\helpers\class-post-type.php :: Line > 72)

    
    /**
    	 * Check if post is explicitly excluded.
    	 *
    	 * @param  int $post_id Post ID to check.
    	 * @return bool
    	 */
    	public static function is_post_excluded( $post_id ) {
    		static $posts_to_exclude;
    
    		if ( ! isset( $posts_to_exclude ) ) {
    			$posts_to_exclude = wp_parse_id_list( Helper::get_settings( 'sitemap.exclude_posts' ) );
    			$posts_to_exclude = apply_filters( 'rank_math/sitemap/posts_to_exclude', $posts_to_exclude );
    		}
    
    		return in_array( $post_id, $posts_to_exclude, true );
    	}
    
    

    Your filter is :

    
    $posts_to_exclude = apply_filters( 'rank_math/sitemap/posts_to_exclude', $posts_to_exclude );
    
    

    But i dont see any hook to use this function.

    What i want to do is use this function via hook to exclude a post via it’s ID. 🙂

    Thanks in advance !

    Hi team !
    Inside “$posts_to_exclude” I’m trying to “array_push()” the id of the post i want to get reed of in the site map but unfortunatly with no success..
    How can i use your existing filter to do that ?

    Thanks in advance.

    Hello,

    Thank you for contacting Rank Math today.

    I am consulting our dev team about this and we will be getting back to you in a short while.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    You can use array_merge function to merge the post ids to existing ids added in the Settings:

    
    add_filter( 'rank_math/sitemap/posts_to_exclude', function( $posts_to_exclude ){
        $posts_ids = [ 333, 999, 111 ]; // Add the post ids you want to exclude seperated by coma.
        return array_merge( $posts_to_exclude,$posts_ids );
    });
    
    

    I hope that helps. Thank you.

    Hello Pratik !
    i was sooo close, since the hook was not in the hook list in the documentation i had not find a solution until your reply, now i figure how to make it work, A great thanks !

    
    add_filter( 'rank_math/sitemap/posts_to_exclude', function( $posts_to_exclude ){
    	$login_designer_page_ID = Login_Designer()->get_login_designer_page()->ID;
      $posts_ids = [ $login_designer_page_ID ]; // You can add all the post ids you want to exclude seperated by coma.
        return array_merge( $posts_to_exclude,$posts_ids );
    });
    
    

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Where is the hook for : posts_to_exclude ?’ is closed to new replies.