Guest User

Untitled

a guest
Jul 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <?php
  2. add_action('init', 'projects_cpt');
  3. function projects_cpt() {
  4.  
  5. $args = array(
  6. 'hierarchical' => true,
  7. 'rewrite' => array('slug' => 'projects'),
  8. 'show_in_nav_menus' => true,
  9. 'labels' => $labels
  10. );
  11.  
  12. register_taxonomy('projectscategory', 'projects', $args);
  13.  
  14. unset($labels);
  15. unset($args);
  16.  
  17.  
  18. $labels = array(
  19. 'name' => 'Projects',
  20. 'singular_name' => 'Project',
  21. 'add_new' => 'Add New',
  22. 'add_new_item' => 'Add New Project',
  23. 'edit_item' => 'Edit Project',
  24. 'new_item' => 'New Project',
  25. 'all_items' => 'All Projects',
  26. 'view_item' => 'View Project',
  27. 'search_items' => 'Search Projects',
  28. 'not_found' => 'No projects found',
  29. 'not_found_in_trash' => 'No projects found in Trash',
  30. 'parent_item_colon' => '',
  31. 'menu_name' => 'Projects'
  32. );
  33. $args = array(
  34. 'labels' => $labels,
  35. 'public' => true,
  36. 'publicly_queryable' => true,
  37. 'show_ui' => true,
  38. 'show_in_menu' => true,
  39. 'query_var' => true,
  40. 'taxonomies' => array('projectstype' ),
  41. 'rewrite' => array('slug' => 'projects/%projectscategory%', 'with_front' => false),
  42. //Adding custom rewrite tag
  43. 'capability_type' => 'post',
  44. 'has_archive' => 'projectsarchives',
  45. 'hierarchical' => false,
  46. 'menu_position' => null,
  47. 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt'),
  48. );
  49. register_post_type('projects', $args);
  50.  
  51. $labels = array(
  52. 'name' => 'Projects Categories',
  53. 'singular_name' => 'Projects',
  54. 'search_items' => 'Search Projects Categories',
  55. 'all_items' => 'All Projects Categories',
  56. 'parent_item' => 'Parent Project Category',
  57. 'parent_item_colon' => 'Parent Project Category:',
  58. 'edit_item' => 'Edit Project Category',
  59. 'update_item' => 'Update Project Category',
  60. 'add_new_item' => 'Add New Project Category',
  61. 'new_item_name' => 'New Project Category',
  62. );
  63.  
  64.  
  65. }
  66.  
  67. ?>
  68.  
  69. <?php
  70. add_filter('post_type_link', 'projectcategory_permalink_structure', 10, 4);
  71. function projectcategory_permalink_structure($post_link, $post, $leavename,
  72. $sample) {
  73. if (false !== strpos($post_link, '%projectscategory%')) {
  74. $projectscategory_type_term = get_the_terms($post->ID, 'projectscategory');
  75. if (!empty($projectscategory_type_term))
  76. $post_link = str_replace('%projectscategory%', array_pop($projectscategory_type_term)->
  77. slug, $post_link);
  78. else
  79. $post_link = str_replace('%projectscategory%', 'uncategorized', $post_link);
  80. }
  81. return $post_link;
  82. }
  83.  
  84. ?>
Add Comment
Please, Sign In to add comment