5

I've created something using reverse tags – when something isn't tagged, it's flagged up to say "Hey! This post hasn't been checked yet!"

Now i'm wondering, is there a way to get the last tag created?

Do tags have modified / created dates? Is there a way of getting around this if they haven't?

The user case I have is security patches for a CMS and I have a team who are documenting everything about it. I want them to create a new tag for the patch, then have a notice display saying "New patch available"

Anyone crossed anything like this before?

1
  • 5
    Tags don't have dates. However, you can save this data in the new term meta table when you create new tags Commented Feb 19, 2016 at 12:17

1 Answer 1

9

Following @PieterGoosen's (credit due) train of thought hook onto the following:

function update_term_timestamps($term_id) {

    switch( current_filter() ) {
        case 'created_term':
            update_term_meta($term_id, '_term_created_at', current_time('mysql', true));
        break;
        case 'edited_term':
            update_term_meta($term_id, '_term_edited_at', current_time('mysql', true));
        break;
    }

}

add_action('created_term', 'update_term_timestamps');
add_action('edited_term', 'update_term_timestamps');

Now the meta data is accessible with:

//for created timestamp...
$timestamp = get_term_meta($term_id, '_term_created_at', true);

//for edited timestamp...
$timestamp = get_term_meta($term_id, '_term_edited_at', true);
8
  • 6
    ... I see a popular plugin in the making here ;-)
    – birgire
    Commented Feb 19, 2016 at 12:56
  • Looking very promising :D Commented Feb 19, 2016 at 13:35
  • 1
    @toscho good idea... sketching out a prototype.
    – Adam
    Commented Feb 19, 2016 at 13:45
  • 1
    @userabuser Imagine being able to query these dates too Commented Feb 19, 2016 at 14:56
  • 2
    @AndrewLazarus on my list too... I'll post back to this thread with a link to the repository when ready.
    – Adam
    Commented Feb 19, 2016 at 14:58

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.