Forums

[resolved] Need help with a hook (2 posts)

  1. Brayne
    Member
    Posted 1 year ago #

    I want to save a timestamp to postmeta when a comment is made on that post. I just can't figure out what hook to use when I want to insert the postmeta...

    Any Ideas?

    thanks in advance.

  2. Brayne
    Member
    Posted 1 year ago #

    Detective work complete.

    My objective was to do a query_posts using meta_key and meta_value_num based on the most recent comment. So I'm storing a timestamp in the postmeta. Here is the code I can up with and it's working great.

    function recent_comment_timestamp() {
    	global $comment_post_ID;
    	$meta_key = 'recent_comment_timestamp';
    	$meta_value = time();
    	update_post_meta($comment_post_ID, $meta_key, $meta_value);
    }
    add_action( 'wp_insert_comment', 'recent_comment_timestamp' );

Topic Closed

This topic has been closed to new replies.

About this Topic