WordPress - get only post content on ajax request


/ Published in: PHP
Save to your folder(s)

If you need on ajax request to get only the post content


Copy this code and paste it in your HTML
  1. <?php
  2. if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  3. if ( have_posts() ) :
  4. // Start the Loop.
  5. while ( have_posts() ) : the_post();
  6.  
  7. ?>
  8. <div data-title="<?php the_title(); ?>"></div>
  9. <?php
  10. get_template_part( 'content', get_post_format() );
  11.  
  12. endwhile;
  13.  
  14.  
  15. else :
  16. // If no content, include the "No posts found" template.
  17. get_template_part( 'content', 'none' );
  18.  
  19. endif;
  20. die();
  21. }
  22. ?>

URL: www.bassta.bg

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.