Edited to rewrite my question
我会尽量说清楚,因为我需要尽快解决这个问题。
我禁用了WordPress的cron,并在我的服务器上添加了一个真正的cron作业来调用wp cron。php每天。但是,我调用的函数不起作用。
代码执行似乎停止于get_posts
, 如果我尝试使用WP_Query
班没有错误消息,之后的任何代码都不会执行。
当我不添加时numberposts
, 但它确实给了我5篇文章,这是numberposts的默认值。
示例:
$posts = get_posts( array(
\'post_type\' => \'post-type\',
\'numberposts\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'tax\',
\'field\' => \'slug\',
\'terms\' => \'term-slug\'
)
)
));
More Info
<帖子类型和分类是在我的插件文件中创建的
init
挂钩当从PHP页面执行时,该函数工作正常,就像我的插件的设置页面一样我试着在
wp_ajax_nopriv
, 和呼叫
admin-ajax.php?action=the-action
来自我的服务器cron,但结果完全相同我还没有尝试保留WP的cron,因为该功能需要很长时间才能执行,您需要访问者通过访问该网站来启动它如果需要更多信息,请回复任何问题/代码请求。
Edit - My loop
set_time_limit( 1800 );
$stores = get_option( \'stores\' );
foreach( $stores as $store_name => $store )
{
$ctime = 0;
$filename = \'\';
$xml_path = \'\';
$dir = dir( $store );
while( false !== ( $entry = $dir->read() ) )
{
$info = pathinfo( $entry );
$ext = strtolower( $info[\'extension\'] );
$filepath = "{$store}/{$entry}";
if( is_file( $filepath ) && $ext == \'xml\' && filectime( $filepath ) > $ctime )
{
$ctime = filectime( $filepath );
$filename = $entry;
$xml_path = $filepath;
}
}
if( file_exists( $xml_path ) && is_file( $xml_path ) )
{
//
//Delete products first
//
$posts = get_posts( array(
\'post_type\' => \'produit-xml\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'succursale\',
\'field\' => \'slug\',
\'terms\' => $store_name
)
)
));
foreach( $posts as $post )
{
$image = get_post_meta( $post->ID, \'nom_photo\', true );
if( $image )
{
$fullpath = ABSPATH . get_option( $store_name . \'-image-path\' );
$fullpath .= \'/resized/\' . $image;
@unlink( $fullpath );
}
wp_delete_post( $post->ID, true );
}
//
//Insert operations follow....
//
}
}