Text fields

Convert textarea ready to store in text column with line breaks etc \n new line characters will still be stored as \n (htmlspecialchars() doens’t convert them to <br>) Convert \n character to <br> when displaying Not needed for a text area (it will respect \n character) but nl2br() is needed when displaying as a general […]

Read More

Other Databases

The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting. Simply create a new wpdb object: And use it in your functions as you do for the wp database:

Read More

template_redirect etc not called

You load a page expecting template_redirect or some other wordpress hook to be called but it isn’t. template_redirect is not fired for wp admin pages. The page is being cached. Some simple webspace hosts do this at the server level even though you explicitly say the page can’t be cached in say the header of […]

Read More

Creating an API URL

You may want a url to be used for say remote devices to connect to your site and pass information using say URL parameters and a response string. You can create a special url and trap it using the code below. However for it to work in all instances you need to have a real […]

Read More

Manipulating Arrays

Remove array entry Inserting New Entry into array Insert at index 0 The rest of the array entries move down if there is already a [0] entry Sort Array https://www.w3schools.com/php/php_arrays_sort.asp Sort by array key ksort() sorts an associative array in ascending order, according to the key

Read More

Using Strings-Values

Convert to int Formatting Numeric Values Leading Zeros Decimal Places Displaying Date And Time Current Date and Time Values you use: click here Get hours now From A String Variable (e.g. a MySQL result) Display as UTC Values you use: click here Convert String to DateTime Display Value As Hex Or the simpler dechex() method […]

Read More

Using Strings-Replace and Insert

Replace Case insensitive str_ireplace() is a case-insensitive version of str_replace() Replace whitespace Replace single and multiple occurrences of white space with a comma Pad string to fixed length

Read More