Reputation: 129
I am using Custom Post type 'listing' and in these post type i have Custom Field Values geocraft_state and geocraft_city.
Currently links are as follows
site.com/listing/Title-of-listing
but i want them to be like this
http://site.com/geocraft_state/geocraft_city/Title-of-Listing
so if someone from NA State post a listing the link should be as follows
site.com/NA/Greensboro/Title-of-Listing
Is their anyway we can use Dynamically Custom Fields Value to generate links?
Any Help will be appreciated.
Thanks
Upvotes: 0
Views: 1491
Reputation: 129
Instead of using Custom Fields i added custom taxonomy for location by adding these codes in functions.php. Now i have to figure out how to show this in Front End Form.
function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('location', 'post', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Locations', 'taxonomy general name' ),
'singular_name' => _x( 'Location', 'taxonomy singular name' ),
'search_items' => __( 'Search Locations' ),
'all_items' => __( 'All Locations' ),
'parent_item' => __( 'Parent Location' ),
'parent_item_colon' => __( 'Parent Location:' ),
'edit_item' => __( 'Edit Location' ),
'update_item' => __( 'Update Location' ),
'add_new_item' => __( 'Add New Location' ),
'new_item_name' => __( 'New Location Name' ),
'menu_name' => __( 'Locations' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'locations', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
Upvotes: 0
Reputation: 1750
The fastest and easiest way with almost 0 coding to do this is to stop using Custom Fields, and set all those fields as Taxonomies \ Categories, hierarchical categories in which geocraft_state would have geocraft_city as children, and using the permalink structure as /%category%/%postname%/
More about taxonomies here: http://codex.wordpress.org/Taxonomies
Upvotes: 1