Site logo

Archived topic

Content Template not updating on loop

7 replies · Started by Diego on December 14, 2021

Viewing posts 1–8 of 8

Hi,

I've created a Content Template to use on my archives for a custom post type and taxonomy.

It's working fine on the default archives.

My problem is in a custom archives template I'm creating for the parent terms in the custom taxonomy.

It's not updating the content template, so it always shows the same post.

This is how I'm using it:


// $topic is the custom taxonomy, I get it from going over get_terms('as_learn_topic', $options) results

$topic_articles = get_posts(array(
        'posts_per_page'    => 4,
        'post_type'         => 'as_learn_article',
        'tax_query'         => array(
            array(
                'taxonomy'  => 'as_learn_topic',
                'field'     => 'term_id',
                'terms'     => $topic->term_id,
            )
        )
    ));

foreach ($topic_articles as $post) :
        // var_dump($post->post_title); --> this shows a different title on each iteration
        generate_do_template_part('archive'); // --> this shows always the same post (is not the first one in the loop btw, looks random)
endforeach;

The thing is, at some point, I saw it working. I don't remember changing anything related to it before it stopped working.

I can't figure out the reason. Maybe am I using the content templates wrong?

Thanks for your time

Hi there,

can you share a link where i can see this loop ?

Thanks, David. I'll try that.

Let us know how you get on!

OK, the hook didn't work, but changing my get_posts() for new WP_Query() and then iterate with while ($latest->have_posts()) : $latest->the_post(); like you're doing seems to work fine.

So maybe the issue was in the type of data get_posts was returning.

Thanks David!

Glad to hear that !!

This archived topic is closed to new replies.