wordpress - Magic Fields (custom post types) and Custom Taxonomy permalink -



i'm using custom post template linked magic fields create custom post type named company.
created custom taxonomy named city. city hierarchical (like categories), , every company has 1 city selected.

for example:
have company post title microsoft , city taxonomy redmond selected. want permalinks this:
http://www.mysite.com/redmond/microsoft

just when have post category , wordpress prepends first category selected permalink.
can done?

i've found solution problem. here code:

add_filter('post_link', 'mba_courses_permalink', 10, 3); add_filter('post_type_link', 'mba_courses_permalink', 10, 3);  function mba_courses_permalink($permalink, $post_id, $leavename) {     if (strpos($permalink, '%mba_courses%') === false) return $permalink;      // post     $post = get_post($post_id);     if (!$post) return $permalink;      // taxonomy terms     $terms = wp_get_object_terms($post->id, 'mba_courses');      if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;     else $taxonomy_slug = 'mba_courses';  return str_replace('%mba_courses%', $taxonomy_slug, $permalink); } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -