Title: How to run code in WordPress
Last modified: July 9, 2020

---

# How to run code in WordPress

 *  [lfbender](https://wordpress.org/support/users/lfbender/)
 * (@lfbender)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/how-to-run-code-in-wordpress/)
 * Whenever I have to run code on the database, change posts, or terms or what have
   you, I am running it on a custom page template.
 * Since this has been working for me up to know, I didn’t think about it much. 
   But I need to delete a ton of terms now from a custom taxonomy and I can’t do
   it on the test page very effectively. Meaning I get 504 gateway errors all the
   time, because the code takes too long to run, and deletes only a part of the 
   terms.
 * So I am wondering, if I need to run custom code to change a lot of data, what
   is the most efficient method to use?
    -  This topic was modified 5 years, 11 months ago by [lfbender](https://wordpress.org/support/users/lfbender/).

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/how-to-run-code-in-wordpress/#post-13111801)
 * It depends upon the scope of the task you need to accomplish. You might be able
   to simply increase the time allocated to execute scripts. Add something like `
   set_time_limit ( 120 );` to wp-config.php. The default is usually 30 sec. I’d
   advise not setting it for too long though, if a coding issue is encountered it
   can be difficult to regain control with very long time limits. You should comment
   out the line (or set it to 30) when your need for extra time is over.
 * I also like using page template code to accomplish special tasks. Things that
   take a long time usually involve querying for data to operate upon. When a lot
   of data is involved I set a limit on the query so my code only operates on the
   first _X_ number of records found. I then just keep reloading the page to repeatedly
   run my script on another chunk of data until no more records are found to work
   upon. The value of _X_ varies depending on the task being done. A few dozen to
   a few hundred records at a time is usually adequate.

Viewing 1 replies (of 1 total)

The topic ‘How to run code in WordPress’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/how-to-run-code-in-wordpress/#post-13111801)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
