Advertisement
Guest User

Untitled

a guest
Sep 26th, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. //=======================================
  4. //Community Posts Permalink Manipulation
  5. //=======================================
  6.  
  7. //fix archive pagination issue.
  8. function community_posts_disable_redirect_canonical($redirect_url) {
  9.   //TODO double check the rules are fine.
  10.   if (is_singular('community_post') || is_page_template('templates/community.php')) $redirect_url = false;
  11.   return $redirect_url;
  12. }
  13.  
  14. //dynamic permalink by community_post_domain slug
  15. function wpa_show_permalinks( $post_link, $post ){
  16.     if ( is_object( $post ) && $post->post_type == 'community_post' ){
  17.         //get the community post domain term (for example: devops)
  18.         $terms = wp_get_object_terms( $post->ID, 'community_post_domain' );
  19.         if( $terms ){
  20.             return str_replace( '%community_post_domain%' , $terms[0]->slug , $post_link );
  21.         }
  22.     }
  23.     return $post_link;
  24. }
  25.  
  26. add_filter('redirect_canonical','community_posts_disable_redirect_canonical');
  27. add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
  28. //==============================================
  29. // END - Community Posts Permalink Manipulation
  30. //==============================================
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement