0

Is it possible to use a variable to rewrite a Custom Post Type permalink FROM wp_terms -> slug?

WPDB: wp_terms -> slug = healthy-living

A1) Current Custom Post Type args:

'rewrite' => array( 'slug' => 'issues/resources' ),

A2) Current Permalink (works great!):

http://localhost/issues/resources/title-of-resource.html

B1) Desired Custom Post Type args (is this possible?):

'rewrite' => array( 'slug' => 'issues/$WP_TERM_SLUG_VAR/resources' ),

B2) Desired Permalink:

http://localhost/issues/healthy-living/resources/title-of-resource.html

If you have any suggestions, your time is appreciated!

2

filter "pre_post_link" to change the permalink rule, the first attribute is the rule set to the administrator and the second is the element which is to form the link

function my_pre_post_link( $permalink, $post, $leavename ) {
  // filtered by post_type, returns the format permalink
  if( $post->post_type != 'book' ) return '/bookis_custom/%postname%';
  return $permalink;
}

add_filter( 'pre_post_link', 'my_pre_post_link', 9, 3 );
  • Please explain your answer rather than just posting a block of code. – s_ha_dum Feb 6 '14 at 17:00
  • @s_ha_dum: I can not write English, but Wordpress XD – Salem Terrano Feb 6 '14 at 17:08
  • 1
    We understand that English may not be the native language for all of our users-- I think non-English is a pretty high percentage actually--, but we still want a "human" explanation rather than just code and Stack policy is "English". Your grammar, spelling, etc. can be, and probably will be, cleaned up by other users. – s_ha_dum Feb 6 '14 at 17:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.