Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This does the trick for Story and Artist, but not for Writer:</p> <pre><code>add_action('init', 'custom_init'); add_filter('post_type_link', 'story_permalink', 10, 3); function custom_init(){ $story = array( 'query_var' =&gt; true, 'rewrite' =&gt; false, ); $artist = array( 'query_var' =&gt; true, 'rewrite' =&gt; true ); $writer = array( 'query_var' =&gt; true, 'rewrite' =&gt; true ); register_post_type('story', $story); register_taxonomy('artist', 'story', $artist); register_taxonomy('writer', 'story', $writer); global $wp_rewrite; $story_structure = '/%artist%/%writer%/%story%'; $wp_rewrite-&gt;add_rewrite_tag("%story%", '([^/]+)', "story="); $wp_rewrite-&gt;add_permastruct('story', $story_structure, false); } function story_permalink($permalink, $post_id, $leavename){ $post = get_post($post_id); $rewritecode = array( '%artist%', '%writer%', $leavename? '' : '%postname%', $leavename? '' : '%pagename%', ); if('' != $permalink &amp;&amp; !in_array($post-&gt;post_status, array('draft', 'pending', 'auto-draft'))){ if (strpos($permalink, '%artist%') !== FALSE){ $terms = wp_get_object_terms($post-&gt;ID, 'artist'); if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) $artist = $terms[0]-&gt;slug; else $artist = 'unassigned-artist'; } if (strpos($permalink, '%writer%') !== FALSE){ $terms = wp_get_object_terms($post-&gt;ID, 'writer'); if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) $writer = $terms[0]-&gt;slug; else $writer = 'unassigned-writer'; } $rewritereplace = array( $artist, $writer, $post-&gt;post_name, $post-&gt;post_name, ); $permalink = str_replace($rewritecode, $rewritereplace, $permalink); } else{ } return $permalink; } </code></pre> <p>Hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload