Guest User

Untitled

a guest
Nov 9th, 2020
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #######
  2. register_post_type( 'px_land', array(
  3. 'labels' => array( 'name' => __( 'Направления' ) ),
  4. 'public' => true,
  5. 'show_ui' => true,
  6. 'capability_type' => 'post',
  7. 'publicly_queryable' => true,
  8. 'exclude_from_search' => false,
  9. 'hierarchical' => true,
  10. '_builtin' => false,
  11. 'query_var' => true,
  12. 'rewrite' => array( 'slug' => '%px_land_cat%', 'with_front' => false ),
  13. 'supports' => array( 'title', 'editor', 'custom-fields' )
  14. ));
  15. register_taxonomy( 'px_land_cat', array( 'px_land' ), array(
  16. 'labels' => array( 'name' => __( 'Категории' ) ),
  17. 'hierarchical' => true,
  18. 'show_ui' => true,
  19. 'query_var' => true,
  20. 'rewrite' => array( 'slug' => 'products', 'with_front' => false )
  21. ));
  22. #######
  23.  
  24. **
  25. * PermaLink - Внедрение терма таксономии в структуру постоянных ссылок для произвольного типа записи.
  26. */
  27. add_filter( 'post_type_link', 'permalink_cpt_product', 10, 2 );
  28. function permalink_cpt_product( $link, $post ) {
  29.  
  30. if ( $post->post_type === 'px_land' ) {
  31. if ( $terms = get_the_terms( $post->ID, 'px_land_cat' ) )
  32. $link = str_replace( '%px_land_cat%', current( $terms )->slug, $link );
  33. }
  34.  
  35. return $link;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment