Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress - how can I fetch more posts via AJAX?
    primarykey
    data
    text
    <p>To begin with, I think this is a longshot but hopefully there is someone out there that can help.</p> <p>To explain the current situation, at the moment I have a custom plugin that grabs various bits of information about a user and their 4 most recent posts.</p> <p>I am also using the WPBook plugin (so this is on facebook and just just a typical wordpress site)</p> <p>Ok, so here is my code that is grabbing the 4 most recent posts for a user:</p> <pre><code>// The Query query_posts('posts_per_page=4&amp;author='.$blogger_id); // set $more to 0 in order to only get the first part of the post global $more; $more = 0; // the Loop while (have_posts()) : the_post(); ?&gt; &lt;div class="oe-grid-box"&gt; &lt;a href="&lt;?php the_permalink() ?&gt;" &lt;?php the_title()?&gt;&lt;/a&gt; &lt;div class="oe-grid-box-content"&gt; &lt;?php echo the_content( '...' ); ?&gt; &lt;/div&gt; &lt;div class="oe-grid-pic"&gt; &lt;a href="&lt;?php the_permalink() ?&gt;"&gt; &lt;span class="&lt;?php echo strtolower($category); ?&gt;"&gt;&lt;/span&gt; &lt;/a&gt; &lt;?php echo $image; ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; // Reset Query wp_reset_query(); ?&gt; &lt;div id="load-more"&gt;Load More&lt;/div&gt; </code></pre> <p>I tried following this tutorial but instead of a separate plugin, placing the code in my existing plugin but now my page won't load:</p> <p><a href="http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/" rel="nofollow noreferrer">http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/</a></p> <p>Ideally, want I want to is when the load more button is clicked, fetch 4 more posts and show them.</p> <p>If anybody could help I'd really appreciate it.</p> <p><strong>UPDATE</strong></p> <p>Ok,</p> <p>so far I've added in my jQuery to call the php file which should hopefully return posts but it doesn't work.</p> <p>I am thinking that it's because it doesn't know what the WordPress functions are?</p> <p>If I put a simple <code>echo</code> in my load more script, the jQuery success function shows an alert to say it worked, but if I start doing WordPress stuff I get an internal server error, this is the code in the load-more.php file:</p> <pre><code>// load wordpress into template $path = $_SERVER['DOCUMENT_ROOT']; define('WP_USE_THEMES', false); require($path .'/wp-load.php'); $blogger_id = $_GET['id']; $firstname = $_GET['firstname']; $surname = $_GET['surname']; $posts = $_GET['posts'] + 4; $category = $_GET['category']; $image = $_GET['image']; // The Query query_posts('paged='.get_query_var('paged').'&amp;posts_per_page=' . $posts . '&amp;author='.$blogger_id); // set $more to 0 in order to only get the first part of the post global $more; $more = 0; // then the same loop as in my page that is making the ajax call. </code></pre>
    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.
 

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