programing

WordPress에서 query_posts의 모든 게시 유형을 가져옵니다.

linuxpc 2023. 3. 22. 20:48
반응형

WordPress에서 query_posts의 모든 게시 유형을 가져옵니다.

사용하고 있다query_posts가장 인기 있는 게시물 목록을 얻습니다.몇 가지 커스텀 투고 타입을 사용하고 있는데, 쿼리에 모두 포함시키는 것이 아니라 추가 작성 시에도 모두 포함시키는 쿼리를 원합니다.

여기 있습니다.

query_posts(array(
    'meta_key' => 'post_views_count',
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
        'post_type' => array('posttype1', 'postype2', 'posttype3')
    )
);

를 포함하지 않으면post_type, 표준 포스트 타입만 취득합니다.post좋은 생각 있는 사람?

사용할 수 있습니다.'post_type' => 'any'모든 포스트 유형에서 가져올 수 있습니다.이 메뉴얼을 참조해 주세요.http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters

주의: 를 사용하는 것을 강력히 권장합니다.WP_Query보다는query_posts. https://wordpress.stackexchange.com/a/1755/27998

'post_type' => 'any',

리비전을 제외한 모든 투고를 가져옵니다.https://developer.wordpress.org/reference/classes/wp_query/ #post-type 파라미터

질문 내용은 다음과 같습니다.

query_posts(array(
    'post_type' => 'any',
    'meta_key' => 'post_views_count',
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
        'post_type' => array('posttype1', 'postype2', 'posttype3')
    )
);

사용하고 싶은 경우get_posts(), 유일한 회피책은,'post_type' => get_post_types()

임의의 투고 유형의 모든 투고를 반환하는 예:

$posts = get_posts([
  'post_type' => get_post_types(),
  'post_status' => 'publish',
  'numberposts' => -1,
]);

언급URL : https://stackoverflow.com/questions/30554730/get-all-post-types-in-wordpress-in-query-posts

반응형