get_posts() not displaying title of current post in single.php
-
<?php $postsdubbed = get_posts(array( 'numberposts' => -1, 'post_type' => 'post', 'category' => $catiddubbed, 'order' => ASC )); ?> <?php if($postsdubbed) {?> <?php foreach($postsdubbed as $post) {?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <hr> <?php } ?> <?php }?>
What this code actually does it doesn’t take the permalink/post title of the post that it’s actually working with at that point in time in the loop, instead it simply takes the permalink/post title of the post that i’m viewing this output from. It’s able to successfully figure out how many posts there are in that category or how many posts that fit the criteria, and it runs the loop that many times, so the output essentially repeats itself.
For example, if that code was put into a custom post type post using a conditional, it doesn’t pull out the posts / their permalinks from the category specified in the get_posts() function, instead it simply takes the permalink/post title of the custom post type post that i’m on and it’ll print it out.
So I think the the_title() and the_permalink() simply won’t work, maybe because it’s in single.php or something. Anyway, I was hoping I could get some type of replacements of these to be used in this loop.
or if someone could shine some light upon why this doesn’t work in the single.php file as it is intended to.
- The topic ‘get_posts() not displaying title of current post in single.php’ is closed to new replies.