I'm working on a news website that has a top section with eight featured articles. I use ACF fields for these featured articles and input their ID. This is how the loop looks:
$kiemelt1 = get_field('kiemelt_1', 'option');
$kiemelt2 = get_field('kiemelt_2', 'option');
$kiemelt3 = get_field('kiemelt_3', 'option');
$kiemelt4 = get_field('kiemelt_4', 'option');
$kiemelt5 = get_field('kiemelt_5', 'option');
$kiemelt6 = get_field('kiemelt_6', 'option');
$kiemelt7 = get_field('kiemelt_7', 'option');
$kiemelt8 = get_field('kiemelt_8', 'option');
$kiemeltek = array($kiemelt1, $kiemelt2, $kiemelt3, $kiemelt4, $kiemelt5, $kiemelt6, $kiemelt7, $kiemelt8);
$args = array(
'posts_per_page' => 8,
'post__in' => $kiemeltek,
);
$wp_query = new WP_Query( $args );
if (have_posts()) {
$i = 0;
while ( have_posts() ) {
the_post();
$i++;
if ($i == 1) {
//Standard html for $kiemelt1
}
if ($i == 2) {
//Standard html for $kiemelt2
}
.... etc.
Now, this populates the section fine, and it works for the most part, but the issue arises when I update the array through the options page.
Example:
I exchange the ID in $kiemelt1
and $kiemelt2
. The articles load, but the order is not updated. Why can this be the case?
What I tried:
I tried changing the conditional so that aside from $i
being a specific number, I double-check for the ID as well:
if ($i == 1 && get_the_id($kiemelt1) ) { }
for example, but this causes the layout to break.
Thanks!
$args
.