3

What I'm trying to do is have a span tag appear on the top of the post type whenever the post is updated.

The way the page is setup, there is a query of different post types that list jobs currently available. Whenever there is a new job posted, there will be a new post in the post grid with the span 'New' that expires after 14 days.

I'm trying to do the same thing but with an 'Updated' span whenever one of these posts are updated.

This is the code that I believe is responsible for the 'New' span.

<?php if (strtotime($post->post_date) > strtotime('-14 days')): ?>
    <div class="new-job-tag"><span>New</span></div>
<?php endif; ?>

I tried to do the same thing for the updated span like so:

<?php if (strtotime($post->the_modified_date) > strtotime('-14 days')): ?>
    <div class="updated-job-tag"><span>Updated</span></div>
<?php endif; ?>

but it doesn't seem to be working.

Am I wrong to assume that this line of code is responsible for the 'New' span?

2
  • 3
    It should be $post->post_modified instead of $post->the_modified_date Commented Feb 23, 2017 at 20:16
  • Yeah, i tried it, but the <div class ="updated-job-tag"> doesn't show up on the DOM.
    – David Kim
    Commented Feb 24, 2017 at 0:36

1 Answer 1

0

No, you're right. This is the code that is responsible for 'New' span:

<?php if (strtotime($post->post_date) > strtotime('-14 days')): ?>
    <div class="new-job-tag"><span>New</span></div>
<?php endif; ?>

The only problem with your modification is that there is no field called the_modified_date in WP_Post object.

The proper name of that field is post_modified, so your code should look like so:

<?php if (strtotime($post->post_modified) > strtotime('-14 days')): ?>
    <div class="updated-job-tag"><span>Updated</span></div>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.