Home > Net >  Should i sanitize $_POST in WP Query?
Should i sanitize $_POST in WP Query?

Time:11-16

I have the WP Query:

$args = array(
    'post_type' => $_POST['type]
);

$query = new WP_Query( $args );

Should i sanitaze $_POST['data'] the WP Query. And how i can do that?

CodePudding user response:

As per the WPCS, you have to sanitize the data

$args = array(
    'post_type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
);

$query = new WP_Query( $args );
  • Related