AJAX content and WordPress functions

I’m trying to load different content into a DIV using AJAX, however none of the WordPress functions work using this method.

I have an list of links which load different content on click using jQuery.
The content is stored in PHP files.

Read More

If I put the code directly in the WordPress page template it works fine, however when loaded with AJAX the WP functions don’t work

This is what I’m trying to load

global $wpdb;
$currentuser_id = get_current_user_id();
$args = array(
                'post_type' => 'location',
                'author' => $currentuser_id,
);                  
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : $query->the_post(); ?>
        <div class="pindex">

            <div class="ptitle">
                <h2><?php echo get_the_title(); ?></h2>
            </div>
        </div>
    <?php endwhile;
    if (  $query->max_num_pages > 1 ) : ?>
        <div id="nav-below" class="navigation">
            <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'domain' ) ); ?></div>
            <div class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'domain' ) ); ?></div>
        </div>
    <?php endif;
endif;
wp_reset_postdata();

Can someone advise on what I need to do to get this to work?

Thanks in advance for any suggestions.

Related posts

Leave a Reply