Copy below code in your function.php file.
Create post type with url taxonomy term
“our_homes” taxonomy terms and “property” Post type.
you must be assign category else it will error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<?php add_action('init', 'wr_property'); function wr_property() { register_taxonomy( 'our_homes', 'property', array( 'label' => 'Taxonomy', 'singular_label' => 'taxonomy', 'hierarchical' => true, 'query_var' => true, 'rewrite' => array('slug' => 'taxonomyname'), ) ); $labels = array( 'name' => _x('Property', 'post type general name'), 'singular_name' => _x('Property', 'post type singular name') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title','editor','thumbnail', 'excerpt'), 'rewrite' => array( //'slug' => 'event', 'slug' => '/%our_homes%', 'with_front' => false //this is must be false for hide post type slug in url ), 'has_archive' => 'property' ); register_post_type( 'property' , $args ); flush_rewrite_rules(); } if($_POST) { add_action('save_post', 'save_details'); //create custom post type } // use this code for taxomy remove from url in custom post yep // in post type set 'with_front' => false add_filter('post_type_link', 'property_permalink_structure', 10, 4); function property_permalink_structure($post_link, $post, $leavename, $sample) { $our_homes_term = get_the_terms( $post->ID, 'our_homes' ); //our_homes taxonomy term if($our_homes_term) { if ( false !== strpos( $post_link, '%our_homes%' ) ) { $post_link = str_replace( '%our_homes%', array_pop( $our_homes_term )->slug, $post_link ); } } return $post_link; } ?> |