AnsPress_Admin::ans_parent_post( integer $post_id, object $post )

Description #

Set answer CPT post parent when saving.

Parameters #

  • $post_id
    integer (Required) Post ID.
  • $post
    object (Required) Post Object.

Changelog #

VersionDescription
2.0.0Introduced.

Source #

File: admin/anspress-admin.php

	public static function ans_parent_post( $post_id, $post ) {
		global $pagenow, $wpdb;

		if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
			return;
		}

		if ( ! current_user_can( 'edit_post', $post->ID ) ) {
			return;
		}

		if ( 'answer' === $post->post_type ) {
			$parent_q = (int) ap_sanitize_unslash( 'post_parent', 'p' );
			if ( empty( $parent_q ) ) {
				return;
			} else {
				$wpdb->update( $wpdb->posts, array( 'post_parent' => $parent_q ), array( 'ID' => $post->ID ) ); // phpcs:ignore WordPress.DB
			}
		}
	}

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