Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

Very similar to this previous question: Changing 'rewrite' argument after custom post type is registeredChanging '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=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

Everything works: hierarchy, rewriting, etc :)

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=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

Everything works: hierarchy, rewriting, etc :)

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=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

Everything works: hierarchy, rewriting, etc :)

Tweeted twitter.com/#!/StackWordPress/status/163226068063490048
"Solved" does not belong in question title
Link
Chip Bennett
  • 55.1k
  • 8
  • 90
  • 170

SOLVED: Change custom post type to hierarchical after being registered

found an answer
Source Link
ragulka
  • 614
  • 2
  • 8
  • 19

SOLVED: 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=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

Everything works: hierarchy, rewriting, etc :)

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?

SOLVED: 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=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

Everything works: hierarchy, rewriting, etc :)

Source Link
ragulka
  • 614
  • 2
  • 8
  • 19
Loading