Unable to retrieve posts in custom loop
-
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
- The topic ‘Unable to retrieve posts in custom loop’ is closed to new replies.