How would go about if I just want a temporary function? (It's a converter just for converting Access to Wordpress tables). I want to execute several times so therefore I want it automated, but I don't know how to execute the function after adding the filter in add_action(). After I'm done converting, I will delete the function.

I want to do something like http://url/index.php?convert

function addcoursecategoriesfromaccess() {
    //code for converting the table

//If I type http://url/index.php?convert then I want the addcoursecategoriesfromaccess()  to execute
if ($_REQUEST['GET'] == 'convert') {

I guess I'm missing something very simple, but as a newbie in WP-programming I hope you can help me out :-) I've the code inside functions.php in the theme.

  • What you are doing (and the answers) isn't really creating a "temporary" function. You are just hooking a function conditionally. The function will still be defined in the code base until you actually delete it from the '.php' file. – s_ha_dum Oct 31 '13 at 15:22
  • @s_ha_dum - What do you mean? I wrote that I will delete the function after I've used it. "After I'm done converting, I will delete the function." – bestprogrammerintheworld Nov 1 '13 at 11:02
  • Yes, the "deleting" is what makes the function temporary but you know that. That isn't really what the question is about. If that were it there would have been no question. You seem to be asking how to hook the function conditionally, though honestly this all seems overly complicated for a temporary conversion process. – s_ha_dum Nov 1 '13 at 13:41

Use e.g. the init hook instead. For instance;:

if (isset($_GET['convert'])) add_action('init', 'yourfunction');

(Come up with a better check, though. ?convert could mean anything. And secure it by checking for user permissions, that it hasn't already run, etc.)


Instead you could hook into init

add_action( 'init', 'addcoursecategoriesfromaccess' );
function addcoursecategoriesfromaccess() {
     if ( ! filter_has_var( INPUT_GET, 'convert' )

     // code here

Then when you want to run it, just go to the URL as you wrote ( {url}/?convert=1 ) and then the addcoursecategoriesfromaccess will run.

  • I think this would work, but I don't believe I should have to execute the function first and then check if convert is set. I believe it should be the other way around. – bestprogrammerintheworld Oct 31 '13 at 9:40
  • @bestprogrammerintheworld If its purely temporary it wont matter if you are going to remove it in the end. – Zogot Oct 31 '13 at 9:45
  • TRUE! But even if it's temporarily I want to do stuff the "right way". I'm a man of principles! :-) Thanks a lot anyway! You've got +1 from me! – bestprogrammerintheworld Oct 31 '13 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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