Wordpress Ajax for newbies


Staff member
I am having issues particularly using Ajax post within an Ajax Post. Please enlighten me if this is possible.

My scenario goes like this.

I am using Wordpress and Bootstrap for my theme. I have a post type for "products" which I want to load using Ajax and have been successfully implemented them individually (for testing purposes) using <a href="https://stackoverflow.com/questions/15402239/how-to-load-wordpress-post-with-ajax-onclick">Wordpress post with Ajax on click</a> as well as using Bootstrap modal to load another Ajax post using <a href="http://wpquestions.com/question/showChrono/id/7922" rel="nofollow noreferrer">Modal via Ajax Post</a>.

I am not a hardcore PHP nor jQuery programmer and I want to know if this 2 can be combined in one code which would be like:

On first click will show the first Ajax post, and on the second click inside the first Ajax post will load Bootstrap modal via Ajax as well.

Here are the format of my initial codes ---


// AJAX POST / stackoverflow.com/questions/15402239/how-to-load-wordpress-post-with-ajax-onclick
// Calls archieve-products.php
    var post_url = $(this).attr("href");
    var post_id = $(this).attr("rel");
        $("#brand-listing").show().html('&lt;div class="loading"&gt;&lt;/div&gt;');
    return false;

// MODAL VIA AJAX POST / wpquestions.com/question/showChrono/id/7922
// Opens modal.php
$('[data-toggle="modal"]').click(function(e) {
    var href = $(this).attr('href');
        if (href.indexOf('#') == 0) {
        } else {
            $.get(href, function(data) {
            $('&lt;div id="brands" class="modal hide fade"&gt;' + data + '&lt;/div&gt;').modal();

HREF from custom page template:

&lt;a href="&lt;?php echo $cpt_onomy-&gt;get_term_link( $term, $term-&gt;taxonomy ); ?&gt;" rel="&lt;?php the_ID(); ?&gt;" class="ajax"&gt;

HREF from archive page template:

&lt;a href="&lt;?php bloginfo('template_url');?&gt;/modal.php?ID=&lt;?php the_ID(); ?&gt;" data-toggle="modal"&gt;

I hope the codes I have provided is enough to help me. <strong>Many thanks in advance :)</strong>