카테고리 없음

[PHP] Wordpress get_permalink 재 작성

행복을전해요 2021. 1. 15. 16:12

드디어 찾았습니다. 코어를 확인하는 경우 https://core.trac.wordpress.org/browser/tags/3.5/wp-includes/link-template.php 모든 필터가 표시됩니다 . 사용자 지정 게시물 유형의 경우 post_type_link필터이고 게시물의 경우 post_link. 코드를 읽으려면 유용한 것들이 많이 있습니다. 내 문제에 대한 해결책은 다음과 같습니다.

define( 'SERVER_ROOT', 'http://' . $_SERVER['SERVER_NAME'] );
define( 'INSTALL_URL', site_url() );

add_filter( 'post_type_link', 'pleasure_post_links', 99 );
function pleasure_post_links( $permalink ) {
  return str_replace( INSTALL_URL , SERVER_ROOT, $permalink);
  }
  

위의 코드는에 대한 링크 http://domain.com/wordpress_folder/custom_post_typehttp://domain.com/custom_post_type만듭니다.

또한 루트 .htaccess (wordpress 폴더가 아닌 루트 폴더)에 필요할 수 있습니다.

RewriteEngine On

RewriteRule   ^blog([^'"]+)?$  ./wordpress_folder/blog/$1 

여기서 blog 는 사용자 지정 게시물 유형 이름이고 wordpress_folder 는 wordpress의 설치 폴더입니다.

누군가에게 도움이 되었으면 좋겠어요. 거의 이틀 동안 해결책을 찾기 위해



출처
https://stackoverflow.com/questions/22006833