2014-09-02 1 views
0

게시 게시물과 다른 게시물 유형에서 "get_post_meta"를 찾고 싶습니다. 여기에 내 코드는 이지만이 게시물 유형의 모든 게시물의 post_meta를 표시합니다! 동일한 슬러그 (post_name)를 가진 게시물을 비교할 수 있다고 생각하지만 어떻게 해야할지 모르겠습니다!게시 게시물과 다른 게시물 유형의 게시물 메타 가져 오기

<?php $sectionscontact = new WP_query(array('post_type' => 'sections-contact', 'post_count'=>1));if ($sectionscontact->have_posts()): while ($sectionscontact->have_posts()) : $sectionscontact->the_post(); $telephone_meta_empty = get_post_meta(451,'telephone', true); 
     if (! empty ($telephone_meta_empty)) { ?> 
      <div class="tp_titre_bloc" style="border-right:1px solid #999999;"> Téléphone</div> 
        <div class="tp_content_bloc"> 
           <?php echo get_post_meta(get_the_ID(), 'telephone', true); ?> 
       </div> 
    <?php } ?> 

답변

0

내가 여기서 한 것은 당신을 위해 그것을 정리하는 것입니다.
posts_per_page과 대조적으로 post_count을 사용하고 있기 때문에이 게시물 유형의 모든 게시물에 대해 post_meta를 표시합니다. 이는 한 검색어에 특정 양의 게시물을 표시하는 올바른 용어입니다. 대신이의 그래서

는 :

<?php 
    $sectionscontact = new WP_query(array(
    'post_type' => 'sections-contact', 
    'post_count' => 1 
    )); 

    if ($sectionscontact->have_posts()): 
    while ($sectionscontact->have_posts()) : 
    $sectionscontact->the_post(); 

    $telephone_meta_empty = get_post_meta(451,'telephone', true); 
    if (! empty ($telephone_meta_empty)) { ?> 
    <div class="tp_titre_bloc" style="border-right:1px solid #999999;">Téléphone</div> 
    <div class="tp_content_bloc"> 
    <?php echo get_post_meta(get_the_id(), 'telephone', true); ?> 
    </div> 
<?php } ?> 

이 원하는 :

<?php 
    $sectionscontact = new WP_query(array(
    'post_type' => 'sections-contact', 
    'posts_per_page' => 1 //changed post_count to posts_per_page 
    )); 

    if ($sectionscontact->have_posts()): 
    while ($sectionscontact->have_posts()) : 
    $sectionscontact->the_post(); 

    $telephone_meta_empty = get_post_meta(451,'telephone', true); 
    if (! empty ($telephone_meta_empty)) { ?> 
    <div class="tp_titre_bloc" style="border-right:1px solid #999999;">Téléphone</div> 
    <div class="tp_content_bloc"> 
    <?php echo get_post_meta($post->ID, 'telephone', true); // changed get_the_id() to $post->ID?> 
    </div> 
<?php } ?> 

가 도움이된다면 알려주세요. WP_Query에

상세 정보 : http://codex.wordpress.org/Class_Reference/WP_Query

감사합니다.

관련 문제