Monday, January 2, 2023
HomeWordPress Developmentwp question - Customized WordPress loop, articles not in identical order as...

wp question – Customized WordPress loop, articles not in identical order as Array


I am engaged on a information web site that has a high part with eight featured articles. I exploit ACF fields for these featured articles and enter their ID.
That is how the loop seems to be:

$kiemelt1 = get_field('kiemelt_1', 'choice');
$kiemelt2 = get_field('kiemelt_2', 'choice');
$kiemelt3 = get_field('kiemelt_3', 'choice');
$kiemelt4 = get_field('kiemelt_4', 'choice');
$kiemelt5 = get_field('kiemelt_5', 'choice');
$kiemelt6 = get_field('kiemelt_6', 'choice');
$kiemelt7 = get_field('kiemelt_7', 'choice');
$kiemelt8 = get_field('kiemelt_8', 'choice');

$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;
    whereas ( have_posts() ) {
        the_post();
        $i++;

   if ($i == 1) { 
       //Commonplace html for $kiemelt1
   }
   
   if ($i == 2) { 
       //Commonplace html for $kiemelt2
   }
   
   .... and many others.

Now, this populates the part positive, and it really works for probably the most half, however the situation arises after I replace the array by the choices web page.

Instance:

I change the ID in $kiemelt1 and $kiemelt2. The articles load, however the order shouldn’t be up to date. Why can this be the case?

What I attempted:

I attempted altering the conditional so that other than $i being a selected quantity, I double-check for the ID as nicely:

if ($i == 1 && get_the_id($kiemelt1) ) { } for instance, however this causes the format to interrupt.

Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments