• Resolved TBRudy3

    (@tbrudy3)


    I am using this plugin to load a series of various feeds dependent on post type.

    There is a navigation ul that looks like this:

    <nav>
        <ul>
              <li id="all"><a href="home" class="ajaxme">Home</a></li>
              <li><a id='ideas' href="/ideas/" class="ajaxme">Ideas</a></li>
              <li><a id='recognition' href="/recognition/" class="ajaxme">Recognitions</a></li>
              <li><a id='job' href="/job/" class="ajaxme">Jobs</a></li>
        </ul>
    </nav>

    Each a inside of the li’s contain a class that triggers an Ajax request like so:

    jQuery(document).ready(function($) {
    
         function load_posts(the_post_type){
    		var data = {
    		  		action: 'post_load',
    		  		security : MyAjax.security,
    		  		the_post_type: the_post_type
    		 };
    		 $('.feed').html('');
    		 $.post(MyAjax.ajaxurl, data, function(response) {
    				var parsed_json = jQuery.parseJSON(response);
    				$('.feed').html(parsed_json);
    
    		});
    		return false;
          }
     	        $('.ajaxme').click( function(){
    		               var the_post_type = $(this).attr("id");
    		               load_posts(the_post_type);
    		               return false;
    	         });
    }); // jQuery Document Ready

    So then each links ID is identical to the post type that I am trying to retrieve.

    Then the php function associated with this is:

    function load_the_posts(){
    	wp_verify_nonce( 'my-special-string', 'security' );
    	$the_post_type = $_POST['the_post_type'];
    	$post_type_data = do_shortcode("[ajax_load_more post_type='$the_post_type' posts_per_page='10']");
    	echo json_encode(do_shortcode($post_type_data));
    	die();
    }
    
    add_action( 'wp_ajax_post_load', 'load_the_posts' );
    add_action( 'wp_ajax_nopriv_post_load', 'load_the_posts' );

    I get a successful response, with the following html populating the feed:

    <section class="feed">
      <div id="ajax-load-more" class="ajax-load-more-wrap default">
    	<ul class="alm-listing " data-repeater="default" data-post-type="job" data-post-format="" data-category="" data-taxonomy="" data-taxonomy-terms="" data-taxonomy-operator="" data-tag="" data-author="" data-search="" data-order="" data-orderby="" data-exclude="" data-offset="0" data-posts-per-page="10" data-scroll="true" data-max-pages="5" data-pause="false" data-button-label="Older Posts" data-transition="slide">
    	</ul>
      </div>
    </section>

    I assume this has something to do with the the ajax plugin file not being able to pick up what is being sent in from the server, and I do not yet have a solution for this.

    Any help would be greatly appreciated.

    https://www.ads-software.com/plugins/ajax-load-more/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi TBRudy3,
    Off the top of my head I would think this is because the Ajax Load More JS would need to be initiated every time you switch post types.

    Currently, the JS functions are not public, but if you look this Github issue (https://github.com/dcooney/wordpress-ajax-load-more/issues/28) it might help you.

    I’m planning to merge those updates once I get some free time, hopefully later this week.

    Thread Starter TBRudy3

    (@tbrudy3)

    Just in case anyone was wondering, I was able to “hack” the situation by just adding the Ajax Load More JS code to my function right after this line:

    $('.feed').html(parsed_json);

    Works fine, but obviously not ideal. I’ll keep a lookout for your updates. Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using custom ajax and shortcode for different views’ is closed to new replies.