2017-09-14 1 views
0

리피터 필드 내에서 특정 확인란이 선택된 모든 게시물을 쿼리하려고합니다. 쿼리 게시물 사용자 정의 필드 : ACF 리피터 내부의 체크리스트

가 나는 이것이 무엇을 내가 원하는 것은 주제 3, 4의 혼합이다 tutorial 발견,하지만 난 내 자신에 의해 달성 할 수없는, 내 첫 번째 시도는 모든 게시물 및 인쇄를 조회 한 점검 항목이었다

<?php 

    $args = array(
     'post_type' => 'modalidade', 
     'posts_per_page' => -1, 
    ); 

    $loop = new WP_Query($args); 

?> 


<?php 

// check if the repeater field has rows of data 
if(have_rows('horarios')): 

    // loop through the rows of data 
    while (have_rows('horarios')) : the_row(); 

     $dia_da_semana = get_sub_field_object('dia_da_semana'); 
     $horario = get_sub_field_object('horario'); 

     if (in_array(1, $dia_da_semana['value'])) { 
      echo 'segunda'; 
      print_r($horario['value']); 
      echo '<br>'; 
     } 

    endwhile; 

endif; 

?> 

하지만 좋은 해결책이라고 생각하지 마십시오. 어쩌면 내가하려는 일을 성취 할 수있는 더 좋은 방법이 있을지도 모른다.

+0

관련 코드를 [Minimal, Complete, Verifiable Example] (https://stackoverflow.com/help/mcve)에 포함하고 질문을 업데이트하여 지금까지 시도한 내용과 작동하지 않는 이유에 대해 자세히 알려주십시오. . – FluffyKitten

+0

완료! 경고를 주셔서 감사합니다! – carmolim

+0

WP 쿼리는 어디에 있습니까? – Aibrean

답변

0

자습서를 사용하여 here을 찾았으며 내 코드와 데이터 구조를 약간 tweked하여 만들었습니다. 마지막 코드는 다음과 같습니다 : 나에게 매우 중요했다

// filter 
function my_posts_where($where) { 

$where = str_replace("meta_key = 'time_%", "meta_key LIKE 'time_%", $where); 
    return $where; 
} 

add_filter('posts_where', 'my_posts_where'); 

// args 
$args = array(
    'posts_per_page' => -1, 
    'post_type'  => 'class', 
    'meta_query' => array(
     array(
      'key'  => 'time_%_day_of_week', 
      'value'  => 'monday', 
      'compare' => 'LIKE' 
     ), 
    ) 
); 

하나의 변화는 모든 게시물을 얻을 수 'posts_per_page' => -1,'numberposts' => -1,를 교체했다. 속성 numberposts이 작동하지 않았습니다.

관련 문제