Trouble with wp_reset_postdata() in Admin Panel


I’m hooking into ‘edit_form_after_editor’

add_action('edit_form_after_editor', 'make_the_button_to_generate_a_report_number');
function make_the_button_to_generate_a_report_number($post) {

Check that I am dealing with a custom post type of ‘publications’

if ($post->post_type != 'publications') return;

Create a number of arguments that I then run in a WP_Query

$new_query = new WP_Query($report_number_args);

use that data to do stuff…
Then I want to reset $post back to how it was, so I run


But $post stays on the last item I had received from my new WP_Query().

What am I doing wrong? Is there a special way to reset the postdata when dealing with a custom post type?

At the beginning and end of the function I have:

echo("<h4>the title = </h4>");

At the beginning the title is the title for the custom post type I clicked on to edit, or blank if I am creating a new post.
At the end the title is always the last post from my query.

SoloCrowd 3 months 0 Answers 13 views 0

Leave an answer