Skip to main content
added testing
Source Link
jetlej
  • 572
  • 1
  • 6
  • 24

Paste this onto any page and load the page (or make it a function in functions.php and call that function somewhere)

$args = array(
    'nopaging' => true, // Loop through all posts at once
    'meta_key' => 'YOUR_CUSTOM_FIELD_NAME', // Replace with the name of your custom field
    'meta_value' => 'YOUR_CUSTOM_FIELD_VALUE', // The value of that field you're matching for
);

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
    
        // Change the status of each post to pending
        $updated = wp_update_post( array('ID' => $the_query->post->ID, 'post_status' => 'pending' ));

        // Check to see if loop is returning posts, and if they were updated
        echo 'Post #' . $the_query->post->ID . ' - ' . $updated;
    }
}

Paste this onto any page and load the page (or make it a function in functions.php and call that function somewhere)

$args = array(
    'nopaging' => true, // Loop through all posts at once
    'meta_key' => 'YOUR_CUSTOM_FIELD_NAME', // Replace with the name of your custom field
    'meta_value' => 'YOUR_CUSTOM_FIELD_VALUE', // The value of that field you're matching for
);

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
    
        // Change the status of each post to pending
        wp_update_post( array('ID' => $the_query->post->ID, 'post_status' => 'pending' ));

    }
}

Paste this onto any page and load the page (or make it a function in functions.php and call that function somewhere)

$args = array(
    'nopaging' => true, // Loop through all posts at once
    'meta_key' => 'YOUR_CUSTOM_FIELD_NAME', // Replace with the name of your custom field
    'meta_value' => 'YOUR_CUSTOM_FIELD_VALUE', // The value of that field you're matching for
);

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
    
        // Change the status of each post to pending
        $updated = wp_update_post( array('ID' => $the_query->post->ID, 'post_status' => 'pending' ));

        // Check to see if loop is returning posts, and if they were updated
        echo 'Post #' . $the_query->post->ID . ' - ' . $updated;
    }
}
Source Link
jetlej
  • 572
  • 1
  • 6
  • 24

Paste this onto any page and load the page (or make it a function in functions.php and call that function somewhere)

$args = array(
    'nopaging' => true, // Loop through all posts at once
    'meta_key' => 'YOUR_CUSTOM_FIELD_NAME', // Replace with the name of your custom field
    'meta_value' => 'YOUR_CUSTOM_FIELD_VALUE', // The value of that field you're matching for
);

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
    
        // Change the status of each post to pending
        wp_update_post( array('ID' => $the_query->post->ID, 'post_status' => 'pending' ));

    }
}