[Resolved] Content Template not updating on loop

Home Forums Support [Resolved] Content Template not updating on loop

Home Forums Support Content Template not updating on loop

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2049149
    Diego

    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

    #2049634
    David
    Staff
    Customer Support

    Hi there,

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

    #2051920
    Diego
    #2051949
    David
    Staff
    Customer Support

    My approach to a similar requirement ( albeit using a shortcode ) was this:

    https://gist.github.com/diggeddy/b71bf07aa55eecb0c34191f9fe05d224

    And i switch my Block Element – Content Template to a Hook and use the Custom hook: db_custom_post_loop

    #2052218
    Diego

    Thanks, David. I’ll try that.

    #2052241
    David
    Staff
    Customer Support

    Let us know how you get on!

    #2052328
    Diego

    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!

    #2052764
    David
    Staff
    Customer Support

    Glad to hear that !!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.