WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] external Loop always returns 'no documents matched query' (4 posts)

  1. roccanet
    Member
    Posted 7 years ago #

    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/.....)

    docroot
    |
    |
    blog

    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]
    </IfModule>

    # 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
    ./blog/2index.php?post=1
    ./blog/2index.php?tag=general
    ./blog/2index.php
    --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?
    thx-sb

  2. Chris_K
    Member
    Posted 7 years ago #

    Not sure if I followed all that, but this article may be helpful: http://codex.wordpress.org/Creating_a_Static_Front_Page

  3. roccanet
    Member
    Posted 7 years ago #

    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?"

    <?php
    define('WP_USE_THEMES', false);
    require('blog/wp-blog-header.php');
    get_header();

    $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 ?>

    <ol>
    <?
    $news=$wpdb->get_results("SELECT
    ID,post_title FROM $wpdb->posts
    WHERE
    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>
    ");
    } ?>
    </ol>

  4. Chris_K
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags