codememo

Wordpress: WP_post_name에 대한 검색 조건 쿼리

tipmemo 2023. 4. 3. 21:32
반응형

Wordpress: WP_post_name에 대한 검색 조건 쿼리

WP_Query(상당히 표준)를 사용하고 있습니다.모든 게 잘 풀려요.

단, 사용자가 URL에 특정 게시물 이름을 입력하면 검색에서 해당 post_name 값에 일치하는 게시물만 반환됩니다.

특정 라인이 작동하지 않는 것에 대한 코멘트와 함께 아래 코드를 참조하십시오.

<?php

$getPeople = array(
    'post_type' => 'person',
    'posts_per_page' => -1,
    // I want this below to only return me the post with this specific value.
    // This doesn't error, but doesn't work either.
    // I know it seems counter-productive to a 'search' but this particular case requires it.
    // This has a hard-coded value at the moment.
    'post_name' => 'rebecca-atkinson',
    'orderby' => 'meta_value',
    'meta_key' => 'last-name',
    'order' => 'ASC',

    'meta_query' => array(
        array(
            'key' => 'gender',
            'value' => $theGender,
        )
    ),

    'tax_query' => array(

        'relation' => 'OR',

        array(
            'taxonomy' => 'accent',
            'field' => 'slug',
            'terms' => $theAccent,
            'operator' => 'IN',
        ),
        array(
            'taxonomy' => 'style',
            'field' => 'slug',
            'terms' => $theStyle,
            'operator' => 'IN',
        ),
        array(
            'taxonomy' => 'age',
            'field' => 'slug',
            'terms' => $theAge,
            'operator' => 'IN',
        ),

    )
);

$myposts = new WP_Query($getPeople);

?>

잘 부탁드립니다.이 특정 'slug'을 검색하는 방법만 볼 수 있다면 좋을 것 같습니다.

고마워요, 마이클

대신

'post_name' => 'rebecca-atkinson',

용도:

'name' => 'rebecca-atkinson',

위의 댓글에 있는 답변 외에 공식 답변으로 올리려고 합니다.

사용해야 합니다.'name'그리고 아니다 'post_name'.

예를 들어 다음과 같습니다.

'name' => 'rebecca-atkinson' 

이것이 미래에 누군가에게 도움이 되기를 바랍니다.

언급URL : https://stackoverflow.com/questions/7600239/wordpress-wp-query-search-criteria-on-post-name

반응형