add_feed and flush_rewrite_rules
You have to check the existing rewrite rules before you run a flush. If your feed name is test, they are stored under the keys ‘feed/(feed|rdf|rss|rss2|atom|test)/?$’ and ‘(feed|rdf|rss|rss2|atom|test)/?$’. So this should do the trick: add_action( ‘init’, function() { $name=”test”; $registered = FALSE; add_feed( $name, ‘test_feed’ ); $rules = get_option( ‘rewrite_rules’ ); $feeds = array_keys( $rules, … Read more