ap_delete_post_activity( WP_Post|integer $post_id )

Description #

Delete all activities related to a post.

If given post is a question then it delete all activities by column activity_q_id else by activity_a_id. More detail about activity delete can be found here @see AnsPress\Activity_Helper::delete()

Parameters #

  • $post_id
    WP_Post | integer (Required) WordPress post object or post ID.

Changelog #

VersionDescription
4.1.2Introduced.

Source #

File: includes/activity.php

function ap_delete_post_activity( $post_id ) {
	$_post = ap_get_post( $post_id );

	// Check if AnsPress posts.
	if ( ! ap_is_cpt( $_post ) ) {
		return new WP_Error( 'not_cpt', __( 'Not AnsPress posts', 'anspress-question-answer' ) );
	}

	$where = array();

	if ( 'question' === $_post->post_type ) {
		$where['q_id'] = $_post->ID;
	} else {
		$where['a_id'] = $_post->ID;
	}

	// Delete all activities by post id.
	return ap_activity_object()->delete( $where );
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment