Have 2 plugins which power some extra woocommerce custom options in WP. Both hook to plugins_loaded.

The 1st plugin is not resetting to the original post data by the looks of things.

One plugin is a sample drop down with the post metaboxes. The plugin queries the db using WP_Query to output a select options box. I run wp_reset_postdata() after.

The second plugin is a different select box which is not pulling with the correct post id so the meta value never correctly saves as the ID is incorrect and also never selects the correct option on load.

Disabling the first sample plugin the second plugin works just like the 1st does because no other queries are running before.

The post data is being requested to be reset but nothing happens.

 public function get_samples_array(){

    $args = array(
        'post_type' => 'product',
        'posts_per_page' => '-1',
        'tax_query' => array(
                    'taxonomy' => 'product_cat',
                    'field' => 'id',
                    'terms' => $this->sample_product_category_id

    $results = new WP_Query( $args );

    if ( $results->have_posts() ) {


        while ( $results->have_posts() ) : $results->the_post();


    return $array;

Above is the section of code I am using.

It just appears that wp_reset_postdata() is not working. Ive tried a variety of things with no success that I am stumped.

I don't want to have to go using something bad practice like intval($_GET['post']) to make it work.

Could it be where I am hooking the plugins that its making wp_reset_postdata() not function as expected?

2 Answers 2


Having attempted various work arounds the way I have this to work is to not use the_post(). WP_Query should still work but I have swapped over to get_posts().

    $results = get_posts( $args );

    foreach ( $results as $p ):

        $array[$p->ID] = $p->post_title;


    return $array;

Frustrating that this seems to be a problem with certain admin pages.

Here is a ticket related to the issue: https://core.trac.wordpress.org/ticket/18408


Old post but the WP ticket still exists, so a workaround is to define $post to a temp variable and reassign it after the query.

global $post    
$tmp_post = $post;

$args = array(...);

$results = new WP_Query( $args );

if ( $results->have_posts() ) {


$post = $tmp_post;

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.