Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a lot of effort, I found the answer, here is a solution for those stuck in the same position.</p> <p>This goes in your plugin page where you are getting posts for a user etc.</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { posts = 8; author_posts = parseInt(&lt;?php echo $author_posts; ?&gt;); $("#link_selector").click(function() { // alert('posts - ' + posts + 'author posts - ' + author_posts); if ((posts - author_posts) &gt; 3) { $("#link_selector").text('No more posts!'); } else { var category = '&lt;?php echo strtolower($category); ?&gt;'; var id = '&lt;?php echo $blogger_id; ?&gt;'; var firstname = '&lt;?php echo $firstname; ?&gt;'; var surname = '&lt;?php echo $surname; ?&gt;'; // alert(posts + category + id + firstname + surname); $.ajax({ type: "GET", url: "/wordpress/wp-admin/admin-ajax.php", dataType: 'html', data: ({ action: 'loadMore', id: id, firstname: firstname, surname: surname, posts: posts, category: category}), success: function(data){ $('#ajax_results_container').hide().fadeIn('slow').html(data); posts = posts + 4; if ((posts - author_posts) &gt; 3) { $("#link_selector").text('No more posts!'); } } }); } }); }); &lt;/script&gt; </code></pre> <p>Then in your theme's functions.php, put your function to do your ajax request:</p> <pre><code>function loadMore() { $blogger_id = $_GET['id']; // get your $_GET variables sorted out // setup your query to get what you want query_posts('posts_per_page=' . $posts . '&amp;author='.$blogger_id); // initialsise your output $output = ''; // the Loop while (have_posts()) : the_post(); // define the structure of your posts markup endwhile; // Reset Query wp_reset_query(); die($output); } </code></pre> <p>Then, just after the closing of your function, put in the action hooks</p> <pre><code>add_action('wp_ajax_loadMore', 'loadMore'); add_action('wp_ajax_nopriv_loadMore', 'loadMore'); // not really needed </code></pre> <p>That's it!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload