Skip to content

Instantly share code, notes, and snippets.

@Ataurr
Last active August 15, 2017 10:54
Show Gist options
  • Save Ataurr/ff0ce45fb9b029216871f524ceba81d4 to your computer and use it in GitHub Desktop.
Save Ataurr/ff0ce45fb9b029216871f524ceba81d4 to your computer and use it in GitHub Desktop.
Change slug in custom post type
register_post_type( 'apb_room_type', apply_filters( 'awe_post_type_room_type', array(
'labels' => array(
'name' => _x( 'Room Type', 'Post Type General Name', 'awebooking' ),
'singular_name' => _x( 'AweBooking', 'Post Type Singular Name', 'awebooking' ),
'menu_name' => __( 'AweBooking', 'awebooking' ),
'all_items' => __( 'All Room Types', 'awebooking' ),
'view_item' => __( 'View Room Type', 'awebooking' ),
'add_new_item' => __( 'Add New Room Type', 'awebooking' ),
'add_new' => __( 'Add New Room Type', 'awebooking' ),
'edit_item' => __( 'Edit Room Type', 'awebooking' ),
'update_item' => __( 'Update Room Type', 'awebooking' ),
'search_items' => __( 'Search Room Types', 'awebooking' ),
'not_found' => __( 'No Room Types found', 'awebooking' ),
'parent' => __( 'Parent Hotel', 'awebooking' ),
),
'description' => __( 'This is where store orders are stored.', 'awebooking' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'hierarchical' => false,
'show_in_nav_menus' => true,
'rewrite' => array( 'slug' => 'apb-room-type' ),
'query_var' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'has_archive' => 'apb_room_type',
'menu_icon' => AWE_BK_BASE_URL_PLUGIN . '/assets/backend/images/calendar.ico', // 'dashicons-calendar-alt',
)
));
//One way with direct function
add_filter( 'awe_post_type_room_type', function($args){
$args['rewrite'] = array( 'slug' => 'room' );
return $args;
});
//TW0 Simple function
function truonght_filter_room_type_args( $args ) {
$args['rewrite'] = array( 'slug' => 'room-type' );
return $args;
}
add_filter( 'awe_post_type_room_type', 'truonght_filter_room_type_args' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment