Rewrite URLs for CPT in domain.com/[archive]/?[query_var]=%post_id% format

I’ve tried unsuccessfully to change the permalinks for a ‘client’ CPT to be like this…

//domain.com/clients/?client_id=123

However, the closest I’ve gotten is…

//domain.com/?client_id=test-client-1

Permalinks are set to plain, but it’s using the slug instead of the post_id. I want the post_id to be used. The CPT should also default to use_front=true, but is not prepending with /clients/.

This is the CPT code I’m using…

function cptui_register_my_cpts_client() {

/**
* Post Type: Clients.
*/

$labels = array(
“name” => __( “Clients”, “bldcrm” ),
“singular_name” => __( “Client”, “bldcrm” ),
);

$args = array(
“label” => __( “Clients”, “bldcrm” ),
“labels” => $labels,
“description” => “”,
“public” => true,
“publicly_queryable” => true,
“show_ui” => true,
“show_in_rest” => true,
“rest_base” => “”,
“has_archive” => “clients”,
“show_in_menu” => true,
“show_in_nav_menus” => false,
“exclude_from_search” => false,
“capability_type” => “post”,
“map_meta_cap” => true,
“hierarchical” => false,
“rewrite” => false,
“query_var” => “client_id”,
“menu_position” => 25,
“menu_icon” => “dashicons-id”,
“supports” => array( “title”, “thumbnail”, “comments”, “author” ),
);

register_post_type( “client”, $args );
}

add_action( ‘init’, ‘cptui_register_my_cpts_client’ );

Read more here:: Rewrite URLs for CPT in domain.com/[archive]/?[query_var]=%post_id% format

Leave a Reply

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