自动立即更新所有帖子

时间:2016-11-17 15:39:09

标签: wordpress

我在创建元框的插件中做了一些更改,我将默认代码添加到元框的“值”中。 数据正在外面发送。我的问题是,现在我需要在每个woocommerce产品上按“更新”,以便永久保存和发送。但我有1500种产品。

我已尝试从常规管理区域进行批量更新,例如Shawn: https://bobwp.com/bulk-edit-posts-wordpress/

它不起作用。所以我尝试了这段代码:

$args = array(
    'posts_per_page' => 1000,
    'post_type' => 'product'
    );
$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) { 
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $casa_id = $post->ID;
        update_post_meta($post->ID, 'casa_id', $casa_id);
    }
}

还有这个:

function woo_zap_update_product_name() {

    if ( ! is_admin() ) {
        return;
    }

    $zap_query = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1 ) );

    if ( $zap_query->have_posts() ) {

        global $post;

        while ( $zap_query->have_posts() ) {
            $zap_query->the_post();
            update_post_meta( $post->ID, '_wc_zap_product_name', $post->post_title );
        }

        wp_reset_postdata();
    }
}
add_action( 'init', 'woo_zap_update_product_name' );

没有工作......还有其他想法吗?

0 个答案:

没有答案
相关问题