Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改产品外接程序WooCommerce中所有产品的post meta?_Php_Wordpress_Woocommerce_Meta_Bulk - Fatal编程技术网

Php 如何更改产品外接程序WooCommerce中所有产品的post meta?

Php 如何更改产品外接程序WooCommerce中所有产品的post meta?,php,wordpress,woocommerce,meta,bulk,Php,Wordpress,Woocommerce,Meta,Bulk,因此,我使用woocommerce,并使用一个名为WP All Import的插件将产品数据库导入我的Quickbooks连接的电子商务平台。现在我需要在完成后将所有产品的meta“\u sync\u status”更改为“on”。在添加所有产品时,我将如何对其执行此操作?您首先需要获取所有WooCommerce产品(post类型的“产品”),循环每个产品,并更新每个产品的post元数据。您可以将此代码放在主题的/wp content/mu plugins“must use”plugins目录中

因此,我使用woocommerce,并使用一个名为WP All Import的插件将产品数据库导入我的Quickbooks连接的电子商务平台。现在我需要在完成后将所有产品的meta“\u sync\u status”更改为“on”。在添加所有产品时,我将如何对其执行此操作?

您首先需要获取所有WooCommerce产品(post类型的“产品”),循环每个产品,并更新每个产品的post元数据。您可以将此代码放在主题的
/wp content/mu plugins
“must use”plugins目录中的
functions.php
文件中,或者匿名使用WordPress Developer+Console之类的插件来运行此代码

// args to fetch all products
$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1
);

// create a custom query
$products = new WP_Query( $args );

// if products were returned...
if ( $products->have_posts() ):
    // loop over them....
    while ( $products->have_posts() ):
        // using the_post() to set up the $post
        $products->the_post();

        // use $post->ID to update the '_sync_status' post meta value
        update_post_meta( $post->ID, '_sync_status', 'on' );
    endwhile; 
endif;
谢谢,这是我的工作 我可以更新和添加新的文章元到我的产品

// args to fetch all products
$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1
);
// create a custom query
$products = new WP_Query( $args );
// if products were returned...
if ( $products->have_posts() ):
    // loop over them....
    while ( $products->have_posts() ):
        $products->the_post();
            if (get_post_meta(get_the_ID(),'slide_template')=="" || !get_post_meta(get_the_ID(),'slide_template')){
                update_post_meta( get_the_ID(), 'slide_template', 'default' );
                echo get_the_ID().' do it'.'<br>';
            }
    endwhile;
endif;
//获取所有产品的参数
$args=数组(
“post_类型”=>“产品”,
“每页帖子”=>-1
);
//创建自定义查询
$products=新的WP_查询($args);
//如果产品被退回。。。
如果($products->have_posts()):
//绕着他们转。。。。
而($products->have_posts()):
$products->the_post();
如果(获取帖子meta(获取帖子ID(),'slide\u template')==“”“”,获取帖子meta(获取帖子ID(),'slide\u template')){
更新发布元数据(获取ID(),“幻灯片模板”,“默认设置”);
echo获取_ID().“执行它”。
; } 结束时; endif;
您可以使用MYSQL中的更新查询来完成此操作。或者在产品循环中使用ADD_META function。Hello@VinaySharma我是一个相对较新的编码员,你能帮我编写代码吗?我需要把它挂到某个东西上还是把它放在那里?如果你把它放在
/wp content/mu plugins/update META.php
中,它会在每次加载页面时运行(所以添加、刷新、删除)。你不需要挂接任何东西。^该目录中的任何文件总是由WordPress执行,“mu”代表“必须使用”