How do I load my custom single-event with Ajax

Home Forums Calendar Products Events Calendar PRO How do I load my custom single-event with Ajax

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #171953
    livog
    Participant

    I am trying to load the single-event.php when I click on a event in the Mini calendar widget.

    Here is what happen in my ajax callback function:


    require_once('../../../wp-load.php');

    if(isset($_GET['url'])) {
    if(!empty($_GET['url'])) {
    $url = $_GET['url'];
    $url = explode('/', $url);

    $arraycount = count($url);
    $event_slug = $url[$arraycount - 2];
    $event_array = tribe_get_event_by_slug($event_slug);

    $event_id = $event_array->ID;

    get_template_part('tribe-events/single-event.php');

    }
    }

    function tribe_get_event_by_slug($event_id, $output = OBJECT) {
    global $wpdb;
    $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='tribe_events'", $event_id ));
    if ( $post ) {
    return get_post($post, $output);
    }
    }

    It only give me alot of errors when I click on the event.

    Here is the Javascript if anyone wanna use that to.

    $(document).on('click','.tribe-mini-calendar-event a', function(e){
    e.preventDefault();

    var url = $(this).attr('href');
    $.ajax({
    data: {
    url: url
    },
    url: "/enterprise/wp-content/themes/igomoon-apollo/testajax.php",
    type: "GET",
    success: function( data ) {
    $('.content').html(data);
    console.log(data);
    }

    });
    return false;

    });

    Any help is appreciate!

    #177620
    Barry
    Member

    Hi!

    I’m afraid we can’t help a great deal with custom development questions like this one – but can you give me a better sense of what errors you are seeing?

    One thing I do notice, unless I’m missing something/it’s catered for in your custom single-event.php template, is that you don’t appear to be setting up the global $post object – if so, any number of functions within the template may fail as they will not “know” which event is being referred to.

    #506017
    Barry
    Member

    Hi! It’s been a while so I’m going to go ahead and close this thread. If we can help with anything else, though, please don’t hesitate to create new threads as needed. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘How do I load my custom single-event with Ajax’ is closed to new replies.