I have this function and a link to a post:
<?php
foreach ($results as $id) {
$post = &get_post( $id->ID );
setup_postdata($post);
<li><a <?php href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
<?php
} ?>
What I want to do is this: if there is a comment posted today, than show me the link to the first comment that has been posted. So for example: if there are 4 comments made today, I want the link to the first comment instead of the permalink just like now.
I tried using this:
<a <?php href="<?php the_permalink(get_comments->$post_id) ?>">postname</a>
and variations of this like comment_post_ID
, but I could not get it to work. What am I doing wrong and what should I do?
I think you may be confused about objects and functions (either that or you copy/pasted in wrong). When you tried to do get_comments->$post_id, that wouldn’t work because get_comments is not an object, get_comments is a function that accepts parameters. Check out what I did below as it may help you:
get_comments() will take a bunch of arguements, in the above I passed it the postID and the count of 1, so that it only pulls the last comment. It will still pull comments not made today though so the if condition I added in should only echo it if the comment was posted after midnight on today.