2016-04-12 5 views
0

:)onlara özel bir alan ekleyin, çöp kutusundan mesajları çıkarın ben aşağıdakileri yapmanız gerekir çöpe tüm mesajların için

1)

2 'yayınla' 'çöp' dan onların durumunu değiştirme 'Silinmiş' değerine sahip yayınlara 'new_status' adlı özel bir alan ekleyin.

İdeal olarak, functions.php içine yerleştirebileceğim bir işlevle ilgilenmem gerekiyor.

ben böyle bir şey ile başlamak gerektiğini düşünüyorum

...

$myconversion = $wpdb->get_row("SELECT * FROM 'wp_posts' WHERE post_status = 'publish'"); 

... ama MYSQL olarak benim güçlü noktası değildir.

Herhangi bir yardım harika olurdu.

cevap

2

Neyse sen güçlü WP_Query fonksiyonu var, bu yüzden böyle bir şey (functions.php dosyasına bu eklemek)

function wp_update_all_posts_status($params = null){ 
    $args = array(
     'nopaging' => true, // Loop through all posts at once 
     'post_status' => array('trash'), //Get posts "from the trash" 
    ); 

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

     while ($the_query->have_posts()) { 
      $the_query->the_post(); 
      // Change the status the post to publish 
      $updated = wp_update_post(array('ID' => $the_query->post->ID, 'post_status' => 'publish')); 
      //add the post "new_status" meta 
      add_post_meta($the_query->post->ID, 'new_status', 'deleted'); 
     } 
    } 
} 

wp_update_all_posts_status(); 
+0

Bravo efendim gerektiğini düşünüyorum, SQL bilmek gerekmez, bu çalıştı kusursuzca. – user3256143

İlgili konular