Load Events List via Ajax

This topic contains 6 replies, has 2 voices, and was last updated by  Tarek Schneider 8 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #24454

    Hi there,

    can you tell me which is the best way to get the Events List (eo-loop-events.php) via an ajax call to load it dynamically? I am despairing since hours. Would be very nice if you could give me a hint.

    Thank you very much.
    Tarek

    Tarek Schneider
    #24461

    Hi Tarek,

    The event list template is more for rendering, but you can try the following:

    //Add a callback to your ajax hook - this will depend on your action variable
    add_action( 'wp_ajax...ajax-hook', function() {
    
         //Set the query based on your ajax request
         $query = query_posts( ... ); //set the query
    
         //loads the template, which prints output
         //you can use object buffering if you need to manipulate or format the output
         eo_locate_template( 'eo-loop-events.php', true, true );
         exit;
    } );
    
    Stephen Harris
    #24706

    That works! Thank you very much! 🙂 Could you tell me as well which query variables I need for searching post titles and preview texts? I couldn’t find the right expression for that. Category and Tag search is working.

    Something like this:

    $args = array(
    ‘post_type’=>’event’,
    ‘showpastevents’=>true,
    ‘posts_per_page’=>-1,
    ‘event-category’=>’SomeCategory’,
    ‘post_title’=>’I am a post title.’, // this isn’t working
    ‘preview_text’=>’aword’, // this isn’t working
    );

    Regards, Tarek

    • This reply was modified 8 years, 2 months ago by  Tarek Schneider.
    Tarek Schneider
    #24710

    Hi Tarek,

    Not sure what you mean by ‘preview_text’ (the excerpt?), but the ‘s’ parameter searches title and content.

    Stephen Harris
    #24711

    Yes, i mean the excerpt! I tried the s parameter, but unfortunately all events are shown although there is no word ‘test’ in the title/text.

          $args = array(
            'post_type'=>'event',
            'showpastevents'=>true,
            'posts_per_page'=>-1,
            'event-category'=>'sport',
            's'=>'test',
          );
          query_posts( $args );
    
          eo_locate_template( 'eo-loop-events.php', true, true ); ?>
    
    • This reply was modified 8 years, 2 months ago by  Tarek Schneider.
    • This reply was modified 8 years, 2 months ago by  Tarek Schneider.
    • This reply was modified 8 years, 2 months ago by  Tarek Schneider.
    • This reply was modified 8 years, 2 months ago by  Tarek Schneider.
    Tarek Schneider
    #24777

    Hi Tarek,

    This works for me. Have you tried deactivating other themes / plug-ins to see if there’s a conflict?

    Stephen Harris
    #24790

    Yes, I cleaned up everything and now it’s working! Thank you for your help!
    Tarek

    Tarek Schneider
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.