• Resolved bburakb

    (@bburakb)


    I’m trying to create custom query with Ajax. Actually it’s working if I write custom code for title, links, featured image, description etc but If I want to use events calendar template, it’s not working.

    ? global $post;

    ? $search = strval( $_POST['search'] );

    ? $posts_per_page = 2;

    ? $paged = isset( $_POST['paged'] ) ? intval( $_POST['paged'] ) : 1;

    ? $args = [

    ? ? ? 'post_status' ? ?=> 'publish',

    ? ? ? 'posts_per_page' => $posts_per_page,

    ? ? ? 's' ? ? ? ? ? ? ?=> $search,

    ? ? ? 'sentence' ? ? ? => true,

    ? ? ? 'ends_after' ? ? => 'now',

    ? ? ? 'paged' ? ? ? ? ?=> $paged,

    ? ];

    ? $events = tribe_get_events( $args );

    ? // make 2nd query to get all relevant posts and use it in 'max_num_pages'

    ? $found_args = $args;

    ? $found_args['fields'] = 'ids';

    ? $found_args['posts_per_page'] = -1;

    ? $found_events = tribe_get_events( $found_args );

    ? ob_start();

    ? ?>

    ? <?php foreach ( $events as $event ) : ?>

    ? ? <?php setup_postdata( $event ); ?>
    /**************************************/
    /***** This Template is not working ***/

    <?php $this->template( 'list/event', [ 'event' => $event ] ); ?>
    /**************************************/

    ? <?php endforeach;

    ? $content_html = ob_get_contents();

    ? ob_end_clean();

    ? wp_reset_query();

    ? $response = array(

    ? ? ? 'content_html' ?=> $content_html,

    ? ? ? 'max_num_pages' => ceil( count( $found_events ) / $posts_per_page ),

    ? );

    ? wp_send_json( $response );

    If I use include or similar, it also not working

     $template_path = locate_template( 'tribe/events/v2/list/event.php' );

    if ( !empty( $template_path ) ) {
    include $template_path;
    } else {
    echo '<p>Event template not found.</p>';
    }

    I already copied template file in the right directory. Query is working if I write a code:

    echo $event->title;

    but I need whole template with right class / div etc. I don’t want to create it manually. I need event calendar event template.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support tristan083

    (@tristan083)

    Hi @bburakb ,

    Thank you for reaching out.

    Have you tried using the Template class to load the template?

    I’d like to note that what you’re trying to accomplish here is beyond our scope of support. A good place to start in finding documentation of our code functions would be our?DevDocs: and our?themer’s guide.

    Thread Starter bburakb

    (@bburakb)

    Because of there is not enough example and explanation in docs, I did not understand.

    I tried these but it did not work.

        foreach ($events as $event) {
    setup_postdata($event);
    // The Events Calendar V2 ?ablonlar?n? kullanarak etkinlikleri yükleyin
    $template = new Tribe\Events\Views\V2\Template('v2/list/event');
    echo $template->template(['event' => $event]);
    }
        foreach ($events as $event) {
    setup_postdata($event);
    // The Events Calendar V2 ?ablonlar?n? kullanarak etkinlikleri yükleyin
    $template = new Tribe__Events__Views__V2__Template('v2/list/event');
    $template->template(['event' => $event]);
    }
           $template = new Tribe__Template();
    $template->template('v2/list/event', ['event' => $event]);

    It did not work but Anyway thanks.

    • This reply was modified 4 months ago by bburakb.
    Plugin Support Darian

    (@d0153)

    Hi @bburakb

    Thank you for your message.

    Let me share this with the team to see if there is a potential workaround or if this is feasible.

    Plugin Support Darian

    (@d0153)

    Hi @bburakb

    Thanks for patiently waiting.

    One of my colleagues just replied and suggested the following:

    Looking at the class View here: wp-content\plugins\the-events-calendar\src\Tribe\Views\V2\View.php

    I think something like this should work. Although, maybe instanciating the class view would be even better.

      ob_start();

    foreach ( $events as $event ) {
    setup_postdata( $event );

    // Use the correct method to render the template
    $view_class = 'Tribe\\Events\\Views\\V2\\View';
    $instance = tribe( $view_class );

    $template = new Tribe__Events__Views__V2__Template( $instance );

    $instance->set_template( $template );
    $instance->set_template_slug( 'list/event' );

    $view_context = tribe_context();

    echo $instance->template( 'list/event', [ 'event' => $event, 'context' => $view_context ] );

    wp_reset_postdata();
    }

    $content_html = ob_get_clean();

    As always, please test it first on your staging site before applying it to your live site.

    Plugin Support Darian

    (@d0153)

    Hi @bburakb

    I hope everything is going smoothly for you. I just wanted to touch base and inquire if you had the opportunity to review my previous response as it has been some time since we last heard from you.

    Looking forward to your reply.

    Plugin Support Darian

    (@d0153)

    Hi there,

    This thread has been inactive for a while, so we’ll go ahead and mark it Resolved. Please open a new thread if any other questions arise, and we’d be happy to help.

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