2014-01-30 7 views
0

나는 http://www.advancedcustomfields.com 플러그인을 사용하고 수천 개의 사용자 정의 게시물을 쿼리하려고합니다.사용자 정의 필드에 값이 있는지 확인하십시오.

나는 게시물에 사용자 정의 필드의 스티커 포스트가 yes로 선택되어 있는지 여부를 확인하는 아래 루프를 가지고 있습니다.

이 작업을 수행하려면 수동으로 수천 개의 게시물을 거쳐 사용자 지정 필드 값이 저장되도록 저장해야합니다.

이 쿼리에 사용자 지정 필드의 값이 있는지 확인하려면 어떻게 추가합니까?

$myposts = get_posts(array(
         'post_type' => 'news', 
         'posts_per_page' => $display, 
         'post_status' => 'publish', 
          'tax_query' => array(
           array(
           'taxonomy' => 'topics', 
           'field' => 'slug', 
           'terms' => array($title)) 
          ), 
         'meta_query' => array(
         'relation' => 'OR', 
           array(
            'key' => 'sticky_post', 
            'value' => 'Yes', 
            'compare' => '!=' 
           ), 
           array(
            'key' => 'sticky_post', 
            'compare' => false 
           )               
         )  
         )); 

답변

0

게시물의 모든 사용자 정의 필드를 얻기 위해이 코드를 시도 - 그래서 나는 사용자 정의 필드 값이 갖고있는 모든 게시물 업데이트 최소한 빈 사용자 정의 필드를 쿼리해야하는 필요성을 없애줍니다.

$topposts1 = get_posts(array(
        'post_type' => 'news', 
        'posts_per_page' => 100000, 
        'post_status' => 'publish')); 

        $featured_count = 0; 
        foreach ($topposts1 as $post) { 
        setup_postdata($post); 

        $field_key = "field_52a1b8b824fff"; 
        $value = "No"; 
        $post_id = $post->ID; 
         update_field($field_key, $value, $post_id); 
        echo $post->post_title; 
        echo "<br />"; 
        } wp_reset_query(); 
1

탄원은 실제로 ACF의 업데이트 기능을 사용하여이 문제를 해결

<?php 

    $custom_fields = get_post_custom(72); 
    $my_custom_field = $custom_fields['my_custom_field']; 
    foreach ($my_custom_field as $key => $value) { 
    echo $key . " => " . $value . "<br />"; 
    } 

?> 
관련 문제