daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. global $wpdb;
  3. $c_results = $wpdb->get_results(
  4.     "
  5.         SELECT *
  6.         FROM wp_postmeta
  7.         WHERE meta_key LIKE '%sub_cells%'
  8.         AND meta_value LIKE '%size-medium%'
  9.     "
  10. );
  11. // var_dump( count( $c_results ) );
  12. if ( ! empty( $c_results ) ) {
  13.     foreach ( $c_results as $key => $c_item ) {
  14.         $c_id        = $c_item->post_id;
  15.         $c_key       = $c_item->meta_key;
  16.         $c_val       = $c_item->meta_value;
  17.         $c_val       = str_replace( '<p>', '', $c_val );
  18.         $c_val       = str_replace( '</p>', '', $c_val );
  19.         $c_val       = str_replace( '<img', '', $c_val );
  20.         $c_val       = str_replace( 'alignnone', '', $c_val );
  21.         $c_val       = str_replace( 'size-medium', '', $c_val );
  22.         $c_val       = str_replace( 'class', '', $c_val );
  23.         $c_val       = str_replace( '=', '', $c_val );
  24.         $c_val       = str_replace( '"', '', $c_val );
  25.         $c_val       = str_replace( 'wp-image-', '', $c_val );
  26.         $c_val       = trim( $c_val );
  27.         $c_val       = explode( ' ', $c_val );
  28.         $c_attach_id = $c_val[0];
  29.         // var_dump( $c_item->meta_value, $c_attach_id );
  30.         $c_img_src   = wp_get_attachment_image_src( $c_attach_id, 'full' );
  31.         // var_dump( $c_img_src );
  32.         $c_new_val   = '<img class="alignnone size-full wp-image-' . $c_attach_id . '" src="' . $c_img_src[0] . '" alt="" width="' . $c_img_src[1] . '" height="' . $c_img_src[2] . '" />';
  33.         // var_dump( $c_new_val );
  34.         // var_dump( $c_id, $c_key, $c_new_val );
  35.         $c_update = $wpdb->update(
  36.             'wp_postmeta',
  37.             array( 'meta_value' => $c_new_val ),
  38.             array( 'post_id' => $c_id, 'meta_key' => $c_key )
  39.         );
  40.         var_dump( $c_update );
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top