programing

WP REST API에 문자열 파라미터 전달

javajsp 2023. 2. 28. 23:15

WP REST API에 문자열 파라미터 전달

WP REST API에 정수값을 전달할 수 있습니다.단, 숫자가 아닌 문자를 전달할 수 없습니다.에러가 납니다.

이게 제가 쓰던...

add_action( 'rest_api_init', function () {
    register_rest_route( 'crowdapi/v1', '/register/(?P<id>\d+)/(?P<username>\d+)', array(
        'methods' => 'POST',
        'callback' => 'userCheck',
    ) );
} );

현악기 다룰 줄 아세요?

내가 직접 찾았어...

사용하다[a-zA-Z0-9-]대신\d현악기 있게

add_action( 'rest_api_init', function () {
    register_rest_route( 'crowdapi/v1', '/register/(?P<id>\d+)/(?P<number>[a-zA-Z0-9-]+)', array(
        'methods' => 'POST',
        'callback' => 'userCheck',
    ) );
} );

이 방법은 효과가 있었습니다./(?P<slug>\w+)

끝점을 정의하려면 아래 코드도 시도해 보십시오.

add_action( 'rest_api_init', function () {
    register_rest_route( 'crowdapi/v1', '/register/(?P<id>\d)/(?P<username>\d)', array(
        'methods' => 'POST',
        'callback' => 'userCheck',
    ) );
} );

이거 먹어봐, 잘 될 거야

add_action( 'rest_api_init', function () {
    register_rest_route( 'crowdapi/v1', '/register/(?P<id>\d+)/(?P<username>\w+)', array(
        'methods' => 'POST',
        'callback' => 'userCheck',
    ) );
} );

언급URL : https://stackoverflow.com/questions/41739288/pass-string-parameters-to-wp-rest-api