Friday, November 4, 2022
HomeWordPress Developmentget template half - get_template_part() doesn't render after the ajax request

get template half – get_template_part() doesn’t render after the ajax request


the whole lot good?

I am making an ajax request and I am utilizing a get_template_part, however I take advantage of the identical get_template_part twice passing the parameters, however the first a part of get_template_part renders the final one, not under I will put the code

<?php
operate listActivities() {
    $time period = get_queried_object();
    $degree = get_field('degree', $time period); 
    $slug = $_POST['slug'];
    $college = $_POST['school'];
    $degree = $_POST['level'];
    $arguments = [        
        'post_type'     => 'events',
        'meta_query'    => [
            'relation'  => 'OR',            
            [
                'key'     => 'unidades',
                'value'   => $school,
                'compare' => '=',
            ],                        
        ],
        'posts_per_page' => -1,
        'orderby'        => 'date',
        'order'          => 'ASC',
        'tax_query' => [
            [
                'taxonomy' => 'evento',
                'field'    => 'slug',
                'terms'    => $slug,
            ],
        ],        
    ];
    

    $ajax_query = new WP_Query( $arguments );

    if ( $ajax_query->have_posts() ):             
        whereas ( $ajax_query->have_posts() ) : $ajax_query->the_post(); 
            $date_end = str_replace("/", '-', get_field('task_day'));
            $convert_day_end = date('Y-m-d', strtotime($date_end));
            $more_day = date('Y-m-d', strtotime("+1days", strtotime($convert_day_end)));
            $end_task = str_replace("/", '-', get_field('end_task'));
            $convert_end_task = date('Y-m-d', strtotime($end_task));
            $end_task_day = date('Y-m-d', strtotime("+1days", strtotime($convert_end_task)));
            $date_day = date('Y-m-d');
            $hyperlink = get_field('link_live');
            if($hyperlink):
                $separar = explode("https://wordpress.stackexchange.com/", $hyperlink);
                $share = str_replace('watch?v=', '', $separar[3]);
                $liveID = explode('=' , $separar[3]);
            endif;
            $provide = get_field('provide');
            $closed_activities = get_field('closed_activities'); ?>

            <article id="task-<?php the_id();?>" <?php post_class($degree);?>>
                <determine>
                    <img src="" alt="">
                    <figcaption>
                        <div class="line"> 
                            <ul>
                                <?php
                                    get_template_part('partials/elements/date-time-task');
                                    get_template_part('partials/elements/location-task');
                                    get_template_part('partials/elements/ticket');
                                    get_template_part('partials/elements/link-task');
                                    get_template_part('partials/elements/reserving');
                                ?>
                            </ul>                                                   

                            <?php
                                get_template_part('partials/elements/share-mobile');
                                get_template_part('partials/elements/button-subscribe', null,
                                    [
                                    'date_day'           => $date_day = date('Y-m-d'), 
                                    'more_day'           => $more_day,
                                    'end_day'            => $end_task_day,
                                    'closed_activities'  => get_field('closed_activities'),
                                    'offer'              => get_field('offer'),
                                    ]
                                );                    
                            ?>   
                        </div>
                        <?php 
                            the_title('<h2>', '</h2>');
                            wp_strip_all_tags(the_content());
                            get_template_part('partials/elements/iframe-video');
                        ?>
                    </figcaption>
                </determine>
                <hr/>

                <?php
                    get_template_part('partials/speakers-mediator', null,
                        $args = [
                            'field' => get_field('posts_speakers'),
                            'title' => 'Palestrante',
                        ]
                    );

                    get_template_part('partials/speakers-mediator', null,
                        $args = [
                            'field' => get_field('posts_mediator'),
                            'title' => 'Mediador',
                        ]
                    );
                    get_template_part('partials/hyperlinks','relational');
                ?>
            </article>
                    
        <?php endwhile;?>
    <?php else:?>
        <article <?php post_class($degree);?>>
            <h2>Nenhum resultado encontrado</h2>
        </article>
    <?php endif; 
    wp_reset_postdata(); 
    wp_reset_query();
    wp_die();
};

add_action('wp_ajax_listActivities', 'listActivities');
add_action('wp_ajax_nopriv_listActivities', 'listActivities');

under my JavaScript code

// Filter in Ajax
let taxEvent = doc.physique.classList.accommodates('tax-evento');
if (taxEvent) {
  var slug = doc.location.pathname.cut up("https://wordpress.stackexchange.com/")[2]
  var degree = doc.querySelector('article.occasions').getAttribute('class').cut up(' ')[0]
  var schoolFilter = doc.querySelector('#filterSchool')

  if(schoolFilter) {
    schoolFilter.addEventListener('change', operate(){
      fetch(wp.ajaxurl, {       
        methodology: 'POST',
        credentials: 'same-origin',
        headers: {
          'Content material-Sort': 'software/x-www-form-urlencoded',
          'Cache-Management': 'no-cache',
        },
        physique: new URLSearchParams({
          motion: 'listActivities',
          slug: slug,
          degree: degree,
          college: this.worth,
        })
      })
      .then(operate(response){
        return response.textual content();
      })
      .then(operate(knowledge){
        doc.querySelector('#listActivities').innerHTML = knowledge
      })
      .catch(operate(error){
        console.log(error)
      })
    });
  }
}

You possibly can verify on the finish that I am utilizing get_template_part(‘speakers-mediator’) twice, however the subsequent one does not work, if I remark the primary time it shows the second, what may very well be occurring? can anyone assist me?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments