programing

특정 템플릿이 있는 워드프레스 쿼리 페이지

easyjava 2023. 3. 5. 10:30
반응형

특정 템플릿이 있는 워드프레스 쿼리 페이지

특정 템플릿이 있는 Wordpress 페이지를 조회하는 방법이 있습니까?여기 내가 얻은 게 있는데 아무것도 안 보여:

<?php $my_query = new WP_Query(array( 'meta_key' => '_wp_page_template', 'meta_value' => 'template-city.php' )); ?>
                <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                    <li>
                    <?php the_title(); ?>
                    </li>
                <?php endwhile; ?>

물론 페이지 템플릿 파일 이름이 있습니다.template-city.php

한다면post_typeWP가 투고를 찾고 당신은 페이지를 찾고 있습니다.

<?php
    $args = array(
        'post_type' => 'page',//it is a Page right?
        'post_status' => 'publish',
        'meta_query' => array(
            array(
                'key' => '_wp_page_template',
                'value' => 'template-city.php', // template name as stored in the dB
            )
        )
    );
$my_query = new WP_Query($args)
?>

언급URL : https://stackoverflow.com/questions/12086998/wordpress-query-pages-with-certain-template

반응형