I'm having difficulty returning a list of posts. This file is contained in a plugin folder (ultimately I want to have a cron job just run the script here to delete posts with invalid urls in the given meta value).

I've tried using get_posts to return posts with no success. So I tried working and reworking a wp_query with still no success.

Also, the only way I can successfully get to the part where the array would be printed and the 'No items here' displays is if the post_status is set to inherit. Otherwise absolutely no output is generated.

Can anyone give me a hint to the fundamental I'm missing here? I've structured the pull correctly both when attempting the get_posts and wp_query because I recycled code structures I already successfully use in other areas of the site. Is there another file I need to call? A special piece of code that has to be added in a stand alone file like this? Another approach I should take?



    global $wp_query;

    $ready_delete = array();

            $query = new WP_Query(array(
                'post_type' => 'cars',
                'posts_per_page' => -1));
            if( $query->have_posts() ) :
                while ($query->have_posts()) : $query->the_post();

                    $checklink_id = get_the_ID();
                    $checklink = get_post_meta($checklink_id, 'ca_link', true);

                    //$ch = curl_init($checklink);
                    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                    //if (curl_exec($ch) === false) {
                         $ready_delete[] = $checklink;
                        //wp_delete_post( $checklink_id, $force_delete );
                    //} else {


                echo 'No items here      ';


  • Apologies; I had to step away just after posting. Attempting suggestions now. Aug 6, 2015 at 16:09

2 Answers 2


This part require('./wp-blog-header.php'); is all kinds of bad idea. And if your file is indeed in plugin folder then header isn't even in that location.

Custom loads of WordPress core are brittle and the technique is typically only justifiable for performance reasons.

It would be better to structure your endpoint via creating actual rewrite endpoint, or making use of admin-ajax.php/admin-post.php.


Did you try including wp-load.php instead of wp-blog-header.php? wp-load.php will load the full WP environment, and set up $wpdb, which you would need before using WP_Query.

Just a thought.

Otherwise, you can also look at wp-cron.php (if you have not done so yet), and see what it does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.