Рассчитать позицию / ранг за возвращенный пост

Вот таможенная декларация

function ts_result_reg() {
$labels = array(
'name' => _x( 'Students Result', 'post type general name' ),
'singular_name' => _x( 'Students Result', 'post type singular name' ),
'add_new' => _x( 'Add New Result', 'result' ),
'add_new_item' => __( 'Add New Result' ),
'edit_item' => __( 'Edit Result' ),
'new_item' => __( 'New Result' ),
'all_items' => __( 'All Results' ),
'view_item' => __( 'View Result' ),
'search_items' => __( 'Search Results' ),
'not_found' => __( 'No result found' ),
'not_found_in_trash' => __( 'No result found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Student Results'
);
$args = array(
'labels' => $labels,
'description' => 'Add new custom post type students result',
'public' => true,
'menu_position' => 5,
'supports' => array( 'thumbnail','title', ),
'taxonomies' => array( 'classes' ),
'has_archive' => true,
'rewrite'=> array ('slug' => 'tscheck'),
);
register_post_type( 'ts_students_result', $args );
}
add_action( 'init', 'ts_result_reg' );

Бэкэнд метабоксы

array(
'name' => 'French',
'id'   => $prefix . 'subject_french_exam_total',
'type' => 'text_small',
// 'repeatable' => true,
),

array(
'name' => 'Business Education,
'id'   => $prefix . 'subject_business_edu_exam_total',
'type' => 'text_small',
// 'repeatable' => true,
),

...

Внешний запрос

 query_posts( array(
...
)
),
'posts_per_page' => 100
)
);
?>
<table style="border:1px solid black" cellpadding="1.5" cellspacing="5">
<tbody>
<tr>
<th><strong>NAME\SUBJECT</strong></th>
<th align='center'><strong>French</strong></th>
<th align='center'><strong>Business Education</strong></th>
<th align='center'><strong>Total</strong></th>
<th align='center'><strong>Average</strong></th>
<th align='center'><strong>Position</strong></th>
</tr>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Initializing count and sum -->
<?php
$subject_count=0;
$subject_sum_total=0;

$subject_french_exam_total= get_post_meta(get_the_ID(),'_ts_subject_french_exam_total',true );
if($subject_french_exam_total):
$subject_count++;
$subject_sum_total+=$subject_french_exam_total;
endif;

$subject_business_edu_exam_total= get_post_meta(get_the_ID(),'_ts_subject_business_edu_exam_total',true );
if($subject_business_edu_exam_total):
$subject_count++;
$subject_sum_total+=$subject_business_edu_exam_total;
endif;

$store_student_avg=array();
if($subject_sum_total>0.1):
$subject_avg_total= $subject_sum_total/$subject_count;
array_push($store_student_avg,$subject_avg_total);
endif;
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php echo $subject_french_exam_total ;?></td>
<td><?php echo $subject_business_edu_exam_total ;?></td>
<td><?php echo $subject_sum_total ;?></td>
<td><?php echo $subject_avg_total ;?></td>

<?php
rsort($store_student_avg);
$arrlength = count($store_student_avg);
$rank = 1;
$prev_rank = $rank;
for($x = 0; $x < $arrlength; $x++)
if ($x==0): ?>
<td><?php echo $rank; ?></td>

<?php elseif ($numbers[$x] != $numbers[$x-1]):
$rank++;
$prev_rank = $rank;
?>
<td><?php echo $rank; ?></td>

<?php else:
$rank++;
?>
<td><?php echo $prev_rank; ?></td>

<?php endif; ?>

</tr>
<?php endwhile;endif; ?>
</tbody>
</table>

Отредактировано: в приведенном выше коде (сокращено) мне нужны позиции (ранг) для каждого среднего пост рассчитывается. Кажется, весь цикл не запускается в WordPress перед выводом, следовательно, вывод для каждого сообщения равен 1 (скриншот вывода). Как мне это решить?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector