Edited to rewrite my question
I'll try to be as clear as possible, as I need to get this resolved quickly.
I disabled WordPress' cron, and added a real cron job on my server to call wp-cron.php every day. The function i'm calling is not working, however.
Code execution seems to stop at get_posts
, same thing if I try using the WP_Query
class. No error message, and any code after just doesn't execute.
When I don't add numberposts
, it does however give me 5 posts, which is the default value for numberposts.
Sample :
$posts = get_posts( array(
'post_type' => 'post-type',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'tax',
'field' => 'slug',
'terms' => 'term-slug'
)
)
));
More Info
- The post type and the taxonomy are created in my plugin file on the
init
hook. - The function works fine when being executed from a PHP page, like my plugin's setting page.
- I tried hooking my function in
wp_ajax_nopriv
, and callingadmin-ajax.php?action=the-action
from my server cron, but with the exact same result. - I haven't tried keeping WP's cron, because the function takes a long time to execute, and you need a visitor launch it by visiting the site.
Please reply with any questions / code request if more information is required.
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....
//
}
}