Admin Page Post Id wp_reset_postdata not working
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(
array(
'taxonomy' = 'product_cat',
'field' = 'id',
'terms' = $this-sample_product_category_id
)
)
);
$results = new WP_Query( $args );
if ( $results-have_posts() ) {
$array[]='None';
while ( $results-have_posts() ) : $results-the_post();
$array[get_the_ID()]=get_the_title();
endwhile;
}
wp_reset_postdata();
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?
Topic wp-reset-postdata wp-query Wordpress
Category Web