Custom Rewrite Rule for Custom Post Type with URL Param

I am trying to create a custom rewrite rule for a custom post type where

This:

http://test.loc/products/directory/?c=some-value

Should become this:

http://test.loc/products/directory/some-value

Minimal code:

function create_post_type() {
register_post_type( ‘acme_product’,
array(
‘labels’ => array(
‘name’ => __( ‘Products’ ),
‘singular_name’ => __( ‘Product’ )
),
‘show_ui’ => false,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(“slug” => “products/directory”)
)
);
add_rewrite_rule(
‘^products/directory/([A-Za-z0-9-]+)/?$’,
‘index.php?post_type=acme_product&c=$1’,
‘top’
);
}

Is there something in the rewrite rule that should be different? I can’t seem to get this to work.

Read more here:: Custom Rewrite Rule for Custom Post Type with URL Param

Leave a Reply

Your email address will not be published. Required fields are marked *