# Change custom post type to hierarchical after being registered

Very similar to this previous question: Changing 'rewrite' argument after custom post type is registered

I am trying to make MarketPress Products hierarchical - I can do it with hacking the plugin files, but I would like to stay away from them if I can.

Is it possible to change arguments of a custom post type after it has been registered, but before all the internal rewrite stuff has been done?

UPDATE: Here's the solution

And as it usually happens, I find the answer a few minutes after posting the question...

So here's what I did in my theme's functions.php file to solve my problem:

function modify_products() {
if ( post_type_exists( 'product' ) ) {

/* Give products hierarchy (for house plans) */
global $wp_post_types,$wp_rewrite;
$wp_post_types['product']->hierarchical = true;$args = $wp_post_types['product'];$wp_rewrite->add_rewrite_tag("%product%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=product&name=");
}
}

Everything works: hierarchy, rewriting, etc :)

-
Ragulka, can you remove the SOLVED from your title and post your solution as an answer. After 24 hours you will be able to accept it. It just makes it easier for people who may have the same / similar problem. Thanks. –  Stephen Harris Jan 27 '12 at 12:54
@ragulka welcome to WordPress Stack Exchange! Please note: this site is not the usual support-forum format, but rather uses a question and answer format, in order to build a robust knowledge base. Questions and answers are posted separately, and are up- and down-voted by the community. The OP "accepts" the answer that best-resolved the original question. So, as Stephen Harris said: please post your solution as an Answer, and then accept that answer. –  Chip Bennett Jan 27 '12 at 15:34
Hey, sorry about that. I actually tried to answer my own question but I couldn't, I was told to wait either 8 hours or add a comment or edit my question instead. So I did. Well, I guess I'll wait another 4 hours and then I can answer my question. –  ragulka Jan 27 '12 at 16:29

And as it usually happens, I find the answer a few minutes after posting the question...

So here's what I did in my theme's functions.php file to solve my problem:

function modify_products() {
if ( post_type_exists( 'product' ) ) {

/* Give products hierarchy (for house plans) */
global $wp_post_types,$wp_rewrite;
$wp_post_types['product']->hierarchical = true;$args = $wp_post_types['product'];$wp_rewrite->add_rewrite_tag("%product%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=product&name=");