0

I have written some php code and using the class.pagination.php, am able to paginate it based on a max posts per page that I set inside my code. This works great.

However, it is only returning 11 posts and I know that I have 186 posts, I am so stuck, any help would be appreciated.

here is my code:

   <?php


define  ("WP_USE_THEMES", false);
define  ("MAX_PER_PAGE", 3);

include ("wp-load.php");
include ("pagination.class.php");

//  posts_per_page=-1

$query = new WP_Query(array('post_type' => 'any'));
$posts = $query->get_posts();

$sAllTitles   = array();
$sAllDates    = array();
$sAllContent  = array();
$iCount       = 0;

foreach($posts as $post) 
{
       $sAllTitles[$iCount] = $post->post_title;
       $sAllDates[$iCount]  = $post->post_date;
       $sAllContent[$iCount]= $post->post_content;
       $iCount++;
}

$iCount = 0;
foreach($posts as $post) 
{
    $PostData[] = array(
    'PTitle' => $sAllTitles[$iCount],
    'PDate'  => $sAllDates[$iCount],
    'PCont'  => $sAllContent[$iCount],
    );
    $iCount++;
}

?>

<html>
<head>
</head>

<body>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BLOG POSTS</title>

<style>

body
{
    font-family : Arial;
    font-size   : 12px;
}

h2
{
    font-family : Arial;
    font-size   : 18px;
    color       : #3279BB;
}

.InfoText
{
    font-family : Arial;
    font-size   : 14px;
}

.pagination 
{
    clear       : both;
    padding     : 20px 0;
    position    : relative;
    font-size   : 11px;
    line-height : 13px;
}

.pagination span, .pagination a 
{
    display     : block;
    float       : left;
    margin      : 2px 2px 2px 0;
    padding     : 6px 9px 5px 9px;
    text-decoration : none;
    width       : auto;
    color       : #fff;
    background  : #555;
}

.pagination a:hover
{
    color       : #fff;
    background  : #3279BB;
}

.pagination .current
{
    padding     : 6px 9px 5px 9px;
    background  : #3279BB;
    color       : #fff;
}

</style>

</head>

<?php

if (count($PostData)) 
{
    $pagination  = new pagination($PostData, (isset($_GET['page']) ? $_GET['page'] : 1), MAX_PER_PAGE);
    $pagination->setShowFirstAndLast(true);

    $PostPages = $pagination->getResults();

    echo $pageNumbers = '<div class="pagination">'.$pagination->getLinks().'</div>';

    if (count($PostPages) != 0) 
    {
        print("<br/>");

        foreach ($PostPages as $PostArray) 
        {
        print ('<div class=\"post\">');
            print ('<h2>' . $PostArray['PTitle'] . '</h2>');

            print ('<div class=\"InfoText\">' . $PostArray['PDate'] . '</div>');

        print ('<div class=\"entry BlogText\">');
        print ($PostArray['PCont']);
        print ('</div>');

        print ('</div>');
        print ('<br/>');
        }

        print ($pageNumbers);
    print ("<br/><br/><br/>");
    }
}


wp_reset_query();
wp_reset_postdata();


?>

</body>
</html>
1
  • 2
    Sorry, but your code is a bit of scramble, difficult to follow. Why aren't you using the main query. You can set posts_per_page with pre_get_posts. If you really need to run a custom query, check how to do it properly with WP_Query Commented Jul 4, 2014 at 13:48

1 Answer 1

1

You can use posts_per_page to return all post from the database Just little modification in your WP query

<?php
$query = new WP_Query(array('post_type' => 'any','posts_per_page'=>-1));
?>

Try with this modification if it works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.