1
먼저 내가 알기보다는 지금까지 내 목표를 말합니다.WordPress (중첩) 게시물 쿼리, 범주별로 반복 한 다음 ACF 단위로
내 목표 : 나는 VisualComposer 작동하는 단축 코드를했습니다
- .
- VC에서이 게시물 유형의 카테고리를 확인할 수 있습니다.
- 짧은 코드의 목표는 선택한 카테고리 당 게시물을 선택하고 정렬하는 것입니다.
- 둘째, ACF 당 나누기 및 정렬. 'custom_field_1'(이)라고 말하십시오.
- 세 번째로 마지막입니다. 게시물을 "custom_field_2"에 알파벳 순으로 정렬 한 다음 "custom_field_3"에 정렬합니다.
예 1
- 적색
- 고양이
- 후 1
- 후 2
- 블루
- 후 3
- 후 4
- 고양이
- 고양이 2
- 적색
- 후 5
- 후 6
- 블루
- 후 7
- 후 8
- 적색
알 오른쪽. 나는 그것을 먼저 시도했다. 그리고 지금까지 내 코드입니다 :
<?php
function productlist_sc($atts){?>
<?php
global $post;
$categories_array = array();
$thecategories = get_categories();
foreach($thecategories as $category){
$categories_array[] = $category->slug;
}
if($atts[ 'category' ]){
$atts[ 'category' ] = explode(",", $atts[ 'category' ]);
}
//collect values, combining passed in values and defaults
$values = shortcode_atts(array(
'category' => ''
),$atts);
$categories = get_categories(array(
'orderby' => 'name',
'parent' => 0,
'slug' => $values['category']
));
$current = get_the_ID($post->ID);
$cargs = array(
//'child_of' => 0,
'orderby' => 'name',
'parent' => 0,
'order' => 'ASC',
'hide_empty' => 1
//'taxonomy' => 'category', //change this to any taxonomy
);
// first sort all selected posts per category
foreach ($categories as $tax) :
// List posts by the terms for a custom taxonomy of any post type
$args = array(
'post_type' => 'products',
'orderby' => 'ASC',
'posts_per_page'=>-1,
'category_name' => $tax->slug
);
$the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<h2>Internal ID: <?php echo $tax->name; ?></h2><?php
// second sort all selected posts per custom_field_1
$mykey_values = get_post_custom_values('custom_field_1');
foreach ($mykey_values as $key => $value) :
?><h3><?php the_field('custom_field_1'); ?></h3>
<div class="rtt_prod_table">
<!-- the loop -->
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div>
<?php if(get_field('custom_field_1') || get_field('custom_field_2') || get_field('custom_field_3')): ?>
<ul>
<?php if(get_field('custom_field_2')): ?>
<li>
<?php the_field('custom_field_2'); ?>
</li>
<?php endif; ?>
<?php if(get_field('custom_field_3')): ?>
<li>
<?php the_field('custom_field_3'); ?>
</li>
<?php endif; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
<?php endwhile; ?> <!-- end of the loop -->
<div><!-- end .accord-content -->
</div>
<?php wp_reset_postdata();
endforeach; // custom_field_1
?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
endforeach; /* end $tax */ ?>
<?php
}