How to show posts in jQuery ui tabs via ajax?
-
Hi, I am using ajax with wordpress for first time. I have a jquery ui tabs, in each tabs i will show differents types of post so i have to run a query_post via ajax. But the functions are shown undefined.
Let me explain:
Here is how i used the jquery ui tabs in ajax mode: https://jqueryui.com/demos/tabs/#Ajax_mode
Tabs:
<ul id="event_control" class="content_tab tabs"> <li><a title="event-tab" href="<?php bloginfo('template_directory'); ?>/ajax/home/event_upcoming.php">Upcoming</a></li> <li><a title="event-tab" href="<?php bloginfo('template_directory'); ?>/ajax/home/event_ongoing.php">Ongoing</a></li> <li><a title="event-tab" href="<?php bloginfo('template_directory'); ?>/ajax/home/event_ended.php">Ended</a></li> </ul>
Container where the content will be loaded:
<div id="event-tab"> </div>
The idea is the when the tab is clicked the jquery will be load the linked php script in the container. Here is one php script that will be loaded.
<?php $query = array( 'post_type' => 'event', 'meta_key' => 'start_time', 'meta_compare' =>'>=', 'meta_value'=>time(), 'meta_key' => 'start_time', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'limit' => 3 ); query_posts($query); if(have_posts()) : while(have_posts()) : the_post(); ?> <div class="content"> <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> <?php if(get_post_meta($post->ID, 'address', true)): ?> <p><span>Address:</span><?php echo get_post_meta($post->ID, 'address', true); ?></p> <?php endif; ?> <small>Remaining: 2 days 12 hours 15 mins and 36 secs</small> </div> <?php endwhile; endif;
The jquery runs the php script in the server but it return the fatal error saying that the query_posts() is undefined. I guess this is not the right way to using ajax in wordpress because it running the particular script and has no idea about any other functions defined in other scripts. Please guide me.
Let me know if anything unclear. Thanks!
- The topic ‘How to show posts in jQuery ui tabs via ajax?’ is closed to new replies.