• shacker

    (@shacker)


    I have a simple PHP script using WP APIs that is called not from a browser but from the command line, as:

    php -f scriptname.php

    It’s working, but something odd happens with the loop. I get the top 5 instances of the_title() and the_content_rss(), but I get the top 20 instances of the_permalink, as if the the_permalink is somehow not part of the same loop. Suggestions welcome, thanks.

    <?php

    query_posts(‘showposts=5’);

    if ($posts) : foreach ($posts as $post) : start_wp();

    the_title();

    the_permalink();

    the_content_rss(”, TRUE, ”, 100);

    ?>

    ———————–

    <?php

    endforeach; else:

    _e(‘Sorry, no posts matched your criteria.’);

    endif;

    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shacker

    (@shacker)

    To clarify: Yes, the script starts with:

    require(‘/path/to/wp-blog-header.php’);

    (otherwise it wouldn’t work at all). The output is like:

    Title1
    permalink1
    stripped content 1
    ———————–
    Title2
    permalink2
    stripped content 2
    ———————–

    Title5

    And then I get 15 of these:

    https://somesite.com/blog/2006/03/18//
    ———————–

    https://somesite.com/blog/2006/03/18//
    ———————–

    https://somesite.com/blog/2006/03/18//

    So those extra permalinks are not even complete. Where are they coming from?

    Thread Starter shacker

    (@shacker)

    Problem solved: I was using the WP 1.2 syntax for the loop. Updated it to a more recent syntax and problem solved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loop question’ is closed to new replies.