function my_custom_post_work() {
$labels = array(
'name' => _x( 'Store', 'post type general name' ),
'singular_name' => _x( 'Store', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Store' ),
'add_new_item' => __( 'Add New Store' ),
'edit_item' => __( 'Edit Store' ),
'new_item' => __( 'New Store' ),
'all_items' => __( 'All Store' ),
'view_item' => __( 'View Store' ),
'search_items' => __( 'Search Store' ),
'not_found' => __( 'No Store found' ),
'not_found_in_trash' => __( 'No store found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Our Store'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our works and work specific data',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'store/%store_location%')
);
register_post_type( 'ss_store', $args );
}
add_action( 'init', 'my_custom_post_work' );
$labels = array(
'name' => 'Cities',
'singular_name' => 'City',
'menu_name' => 'City',
'all_items' => 'All Cities',
'parent_item' => 'Parent City',
'parent_item_colon' => 'Parent City:',
'new_item_name' => 'New City Name',
'add_new_item' => 'Add New City',
'edit_item' => 'Edit City',
'update_item' => 'Update City',
'separate_items_with_commas' => 'Separate City with commas',
'search_items' => 'Search Cities',
'add_or_remove_items' => 'Add or remove Cities',
'choose_from_most_used' => 'Choose from the most used Cities',
);
$args = array(
'labels' => $labels,
//'hierarchical' => false,
'public' => true,
'show_ui' => true,
'query_var' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'has_archive' => true
);
register_taxonomy( 'city', 'ss_store', $args );
}
add_action( 'init', 'mav_taxonomies_work', 0 );
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
function filter_post_type_link( $post_link, $id = 0, $leavename = FALSE ) {
if ( strpos('%store_location%', $post_link) === 'FALSE' ) {
return $post_link;
}
$post = get_post($id);
if ( !is_object($post) || $post->post_type != 'ss_store' ) {
return $post_link;
}
$terms = wp_get_object_terms($post->ID, 'store_location');
if ( !$terms ) {
return str_replace('store/%store_location%/', '', $post_link);
}
return str_replace('%store_location%', $terms[0]->slug, $post_link);
}
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_action( 'wp_loaded','my_flush_rules' );
/// flush
function my_flush_rules(){
$rules = get_option( 'rewrite_rules' );
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Also, you will have to write rewrite rules for your custom post type for your proposed URI structure to work.
// Add the below code to your theme's functions.php file:
`
// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
$newrules = array();
$newrules['store/?$'] = 'index.php?post_type=ss_store';
$newrules['store/page/?([0-9]{1,})/?$'] = 'index.php?post_type=ss_work&paged=$matches[1]';
$newrules['store/(.+?)/page/?([0-9]{1,})/?$'] = 'index.php?post_type=ss_store&city=$matches[1]&paged=$matches[2]';
//print_r($rules);
return $newrules + $rules;
this is the code I used... permalinks are formatted as wanted but now template not loading...404