I’m using wp_insert_post
to programmatically add content to a site. This works fine with posts, categories and tags, but not with pages.
When I attempt to add a page (i.e. post with post_type=page), the rewrite rules do not get properly regenerated (or something happens to them after wp_insert_post
). Specifically, rules related to category and tag urls get lost, as listed below:
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
…etc
This means that tag and category archive urls get broken. Just clicking on Settings > Permalinks will repair them. Have tried to fix by using $wp_rewrite->flush_rules()
immediately after wp_insert_post
but this has not fixed the problem…