How to pass extra variable in wordpress admin post.php

766

i want to pass variable post edit url in edit.php by default this is the link

http://wordpresssite.com/wp-admin/post.php?post=62&action=edit"

I want to add one or more variable in this url like

http://wordpresssite.com/wp-admin/post.php?post=62&action=edit&post_type=newproduct"

when the user click anyone of the post listed in all post it will redirect to post.php with new variables how can we do this?

27

Answer

Solution:

Following code will do the job:

add_action('add_meta_boxes_post', 'add_extra_param');

function add_extra_param( $post ){

 if(!isset($_REQUEST['new_param'])){
       ?>
       <script type="text/javascript">
            window.location = window.location.href + '&new_param=new_value';
       </script>
       <?php
 }

}

If you want to specify a post type before appending a parameter, you can use 'add_meta_boxes' hook. See, here the details of both the hooks i.e. 'add_meta_boxes_post' and 'add_meta_boxes': http://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes

Though you don't have to deal with meta boxes here, these hooks run when you access any post in the admin area.

People are also looking for solutions to the problem: PHP Array duplicate data count

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.