Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Devtard

    (@devtard)

    It may be possible. Here is the code responsible for tagging posts when publishing or saving posts (beginning with line 343 in v1.5):

    if($apt_settings['apt_tagging_hook_type'] == 1){
    	add_action('publish_post','apt_single_post_tagging'); //executes the tagging script after publishing a post
    }
    else{ //trigger tagging when saving the post
    	add_action('save_post','apt_single_post_tagging'); //executes the tagging script after saving a post
    }

    Try adding a new action with the hook “comment_post” instead of “publish_post” or “save_post”. I haven’t tested it, but all you need is to pass the post ID to the function “apt_single_post_tagging” when a new comment has been added. If that hook doesn’t work, ask for help on the forums (there are people who know hooks better than me and who can find the right one).

    Thread Starter MarketRaisen2

    (@marketraisen2)

    I’ll have a look just now.

    Thread Starter MarketRaisen2

    (@marketraisen2)

    No luck at all here, tried comment_post and wp_insert_comment, I’ll keep going though.

    Thans for the reply Devtard

    Plugin Author Devtard

    (@devtard)

    This code will do the job:

    function apt_new_comment_tagging($post_id){
    	$article_id = get_comment($post_id);
    	apt_single_post_tagging($article_id->comment_post_ID);
    }
    
    add_action('comment_post', 'apt_new_comment_tagging');

    The whole thing should look similar to this:

    function apt_new_comment_tagging($post_id){
    	$article_id = get_comment($post_id);
    	apt_single_post_tagging($article_id->comment_post_ID);
    }
    
    if($apt_settings['apt_tagging_hook_type'] == 1){
    	add_action('comment_post', 'apt_new_comment_tagging');
    
    //	add_action('publish_post','apt_single_post_tagging'); //executes the tagging script after publishing a post
    }
    else{ //trigger tagging when saving the post
    	add_action('save_post','apt_single_post_tagging'); //executes the tagging script after saving a post
    }

    In this case, the post won’t be tagged when published, only when a new comment is made. (Every time someone adds a comment, the tagging function will process the post. You may want to a avoid that by adding a condition that executes the code only if no comment has been added yet.)

    Thread Starter MarketRaisen2

    (@marketraisen2)

    Yep, this works, thank you for the help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto tag a post after a comment is made.’ is closed to new replies.