• Resolved vdeegan

    (@vdeegan)


    Hi,

    I’m trying to make a utility for automating some of my post maintenance tasks. And I put in the basic loop structure for looping through all my posts. But, when I try to get the content of a post during an iteration, I never get anything. I’m not using the usual statements for displaying my posts because I’m not interested in displaying anything. I just want to use the data. So, for example, instead of using the_post, I use get_post(PostID), and instead of the_content, I use get_the_content(), and so on.
    The results I get, are always blank, except for the PostID. The get_the_ID() function always returns 888 for every iteration eventhough I give 1,2,3.. for my PostID parameter in get_post().
    Apparently, I’m not reaching the area where my posts are.
    Below, is a beginning excerpt of my code. (Using a for loop now instead of a while loop to limit my iterations just to get something to work first.)

    <?php if (have_posts()) { for ($i=1; $i <=5; $i++) { get_post($i); ?>
    
         <?php 
    
    	// If not done already, get the author name of the YT post on
            // YT itself, add author name to post content, and add
            // "author" to post tags.
    
    	$content_string = get_the_content();
    	$postID = get_the_ID();
    	$post_tags_array = wp_get_post_tags($postID);
    	$auth_tag_string = "author";
    
            ....
            ....
            .... and so on					
    
         } //for
         } //if
    
         ?>

    Thank you for any help.
    Vince Deegan

Viewing 5 replies - 1 through 5 (of 5 total)
  • The get_post() function requires a post ID as a parameter. You are passing in an integer that does not match any posts. Stick to the usual if (have_posts()): while (have_posts()): the_post(); construct.

    Thread Starter vdeegan

    (@vdeegan)

    Stick to the usual if (have_posts()): while (have_posts()): the_post(); construct.

    Thank you for the response. I brought it back to the original way. But, still, I’m not getting any posts. Is there some preliminary steps I need to take in order to establish communication with the dataase? Here’s the revised code:

    <?php if (have_posts()) { while (have_posts()) { the_post(); ?>
    
       <?php 
    
    	// If not done already, get the author name of the YT post on
            // YT itself, add author name to post content, and add
            // "author" to post tags.
    
    	$content_string = get_the_content();
    	$postID = get_the_ID();
    	$post_tags_array = wp_get_post_tags($postID);
    	$auth_tag_string = "author";
    
            ....
            ....
            .... and so on					
    
         } //while
         } //if
    
         ?>

    Thanks again for any further help.
    Vince

    Thread Starter vdeegan

    (@vdeegan)

    Sorry for not mentioning this in the beginning. The method I’m using for invoking my PHP code is by making it the template file for a private page I added to my blog. When I access that page, the php code starts running. Also, the debugger I’m using is FirePHP (on my Firefox browser).
    Vince

    If you posted the complete code above, you probably need a query_posts() call before the if have_posts(), something like this:

    <?php query_posts('posts_per_page=-1'); ?>
    <?php if (have_posts()) { while (have_posts()) { the_post(); ?>
    Thread Starter vdeegan

    (@vdeegan)

    If you posted the complete code above, you probably need a query_posts() call before the if have_posts(), something like this:

    <?php query_posts(‘posts_per_page=-1’); ?>
    <?php if (have_posts()) { while (have_posts()) { the_post(); ?>

    vtxyzzy,
    Your a genius! It’s now accessing my posts and getting me all the data I’m looking for.
    Thank you so much for your help.
    Take care.
    Vince

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Unable to retrieve posts in custom loop’ is closed to new replies.