Support » Fixing WordPress » external Loop always returns ‘no documents matched query’

  • Resolved roccanet


    Hello wpeeps,

    Having some issues getting the Loop to work externally of the default index.php file.

    i have a new install of latest wp 2 that is working correctly with permalinks on.

    My wp base directory is one directory under the docroot (/docroot/blog/wp-content/…..)


    I have apache Override All set and my .htaccess file in the /docroot/blog directory looks like this (i believe this is out of the box as well):

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    # END WordPress

    What i am trying to do is get access to the Loop in my docroot directory. So in testing this i have followed the Loop examples and even tried to copy the blog/index.php file to docroot and even to another named file in the /blog directory – ‘./blog/2index.php’.

    However i access this file through a browser – ./blog/2index.php?p=1
    –moving the file up a directory and modifying the include path for wp-blog-header.php – same results.

    Any requests to these pages always returns “Sorry, no posts matched your criteria.”

    I am certain i have correctly included the ./blog/wp-blog-header.php and my file reads data from this header file.

    Anyone have any troubleshotting ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Not sure if I followed all that, but this article may be helpful:

    Excellent pointer! thanks handysolo.

    As a note for others that were having a similar problem as me – in my case i could not seem to get the Loop wrapper with permalinks running to return post data on any file outside of the default index.php installed WP file.

    This bit of code from HS’s post pointer above allowed me to access WP posts and functions correctly on an external static page:

    With hindsight 20/20 – i should have originally posted -“How can i access WP objects without using the Loop wrapper?”

    define('WP_USE_THEMES', false);

    $how_many=2; //How many posts do you want to show
    require_once("blog/wp-config.php"); // Change this for your path to wp-config.php file ?>

    ID,post_title FROM $wpdb->posts
    post_status= "publish" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    print ("
    <li><a href="");
    echo get_permalink($np->ID);
    print ("">$np->post_title</li>
    } ?>

    Excellent – glad you got it sorted! Please mark this one “resolved” (up at top) and happy blogging!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘external Loop always returns ‘no documents matched query’’ is closed to new replies.