php - Rewrite Wordpress url in CUSTOM POST TYPE -


i have horoscope post type, have 4 categories (yearly, monthly, lovely , weekly horoscope) every post have 12 editors - 12 signs. need url structure:

  1. in yearly need url: http://domain.com/post-type/taxonomy/year
  2. in monthly need url: http://domain.com/post-type/taxonomy/month/year
  3. in lovely need url: http://domain.com/post-type/taxonomy/month/year
  4. in weekly need url: http://domain.com/post-type/taxonomy

in yearly have many years, in monthly , lovely have many years , many month, in weekly on page edit every week.

at first think "taxonomy" - parent category of taxonomy, "month" - child category of taxonomy , "year" - post. when create in on taxonomy same name of category slug became "month-1, month-2" , same when create same post name in post type. solution doesn't work.

now want create 4 post type , in each post type rewrite url, that:

  1. in yearly need in url show: http://domain.com/horoscope/post-type/year-of-post create , no slug of post
  2. in monthly , lovely need in url show: http://domain.com/horoscope/post-type/month-of-post-create/year-of-post-create/ , no slug of post
  3. in weekly just: http://domain.com/horoscope/weekly/

now create 4 post type , rewrite url code:

global $wp_rewrite; $kuukausihoroskooppi_structure = '/horoskoopit/kuukausihoroskooppi/%monthnum%/%year%/%kuukausihoroskooppi%'; $wp_rewrite->add_rewrite_tag("%kuukausihoroskooppi%", '([^/]+)', "kuukausihoroskooppi="); $wp_rewrite->add_permastruct('kuukausihoroskooppi', $kuukausihoroskooppi_structure, false); // add filter plugin init function add_filter('post_type_link', 'kuukausihoroskooppi_permalink', 10, 3); // adapted get_permalink function in wp-includes/link-template.php function kuukausihoroskooppi_permalink($permalink, $post_id, $leavename) { $post = get_post($post_id); $rewritecode = array(     '%year%',     '%monthnum%',     '%day%',     '%hour%',     '%minute%',     '%second%',     $leavename? '' : '%postname%',     '%post_id%',     '%category%',     '%author%',     $leavename? '' : '%pagename%', );  if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {     $unixtime = strtotime($post->post_date);      $category = '';     if ( strpos($permalink, '%category%') !== false ) {         $cats = get_the_category($post->id);         if ( $cats ) {             usort($cats, '_usort_terms_by_id'); // order id             $category = $cats[0]->slug;             if ( $parent = $cats[0]->parent )                 $category = get_category_parents($parent, false, '/', true) . $category;         }         // show default category in permalinks, without         // having assign explicitly         if ( empty($category) ) {             $default_category = get_category( get_option( 'default_category' ) );             $category = is_wp_error( $default_category ) ? '' : $default_category->slug;         }     }      $author = '';     if ( strpos($permalink, '%author%') !== false ) {         $authordata = get_userdata($post->post_author);         $author = $authordata->user_nicename;     }      $date = explode(" ",date_i18n('y f d h s', $unixtime));     $rewritereplace =         array(             $date[0],             $date[1],             $date[2],             $date[3],             $date[4],             $date[5],             $post->post_name,             $post->id,             $category,             $author,             $post->post_name,         );     $permalink = str_replace($rewritecode, $rewritereplace, $permalink); } else { // if they're not using fancy permalink option } return $permalink; } 

for yearly post type don`t need %monthum% in url in post type in code:

$kuukausihoroskooppi_structure = '/horoskoopit/kuukausihoroskooppi/%monthnum%/%year%/%kuukausihoroskooppi%'; 

i remove %month%/ , post type work url http://domain.com/horoscope/post_type/year_of_post/post_slug template: single-post_type.php don`t need post-slug, remove %kuukausihoroskooppi%, page show archive.php;

but post type monthly , lovely wich url %monthum% redirect 404 page , dont show.

what better do?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -