AnsPress_Admin::ans_parent_post( integer $post_id, object $post )
Description #
Set answer CPT post parent when saving.
Parameters #
- $post_idinteger (Required) Post ID.
- $postobject (Required) Post Object.
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
}
}
}
Expand full source code Collapse full source code View on GitHub: admin/anspress-admin.php:387
Add your comment