Categories
Programming

Finding, Deleting and Cleaning Orphaned Post Meta in WordPress

NOTE: Please remember to backup your database before doing any SQL level deletes. Over time, the wp_postmeta table can get littered with a number of records. These linked meta data rows are not always removed when posts from the wp_posts table are deleted. While WordPress has well optimised the wp_postmeta table, it might be wise […]

Categories
Programming

Which mode of MySQL WEEK() complies with ISO 8601 and matches PHP’s DATE function

To mix MySQL week numbers with PHP, can be a bit confusing. The best way to get a relevant match is to use mode 3 in the MySQL WEEK() function. For example, in PHP: [php] date(‘W’, strtotime(‘2019-12-31’)); Returns: 01 date(‘W’, strtotime(‘2020-12-31’)); Returns: 53 date(‘W’, strtotime(‘2021-12-31’)); Returns: 52 [/php] The same in MySQL: [sql] SELECT WEEK(‘2019-12-31’, […]

Categories
Programming

SugarCRM / SuiteCRM – Adding created_by and modified_user_id using SugarBean

If you are a big fan of using SugarBean to handle CRUD (Create Read Update Delete) operations, you might have noticed that the created_by andĀ modified_user_id values are automatically provided by the underlying code logic. You can bypass this logic and override the UserIDs. Below is the example PHP code: [php] $bean->set_created_by = false; $bean->update_modified_by = […]

Categories
Programming

Magento – Inspect the Data Passed Through Observer Events

[php] echo "<pre>"; var_dump($observer->getDataObject()->getData()); [/php]

Categories
Programming

Magento – Show Address Fields in Customer Registration Form

Open up your local.xml or any xml file that you are using with your theme. Add the following bit: [xml] <customer_account_create> <reference name="customer_form_register"> <action method="setShowAddressFields"> <param>true</param> </action> </reference> </customer_account_create> [/xml] You will notice a code in the register.phtml file found here: /app/design/frontend/base/default/template/customer/form/register.phtml [php] if($this->getShowAddressFields()): [/php] This is the condition that shows the customer address related […]

Categories
Programming

WordPress Fix – the_date() Function Returning Blank Value

Are you are using the_date() function in WordPress templates and getting a blank or empty value? When more than one post is published on the same day, the_date() function displays only the date for the first post in the loop. The right way to handle this is by using the the_time() function. Try this: [php] […]

Categories
Programming

Vagrant – Removing VM from Global Status after Deleting Folder and Files

You might have deleted the folders and files for a Vagrant virtual machine. However, you will see the machine appear under the ‘vagrant global-status’ command. If you issue the command ‘vagrant destroy [virtualmachineid]’, you will get the following message “The working directory for Vagrant doesn’t exist! This is the specified working directory:” To remove the […]

Categories
Programming

Magento – Get Current Package Name and Theme Name

[php] // To get the current package name of the Magento store / site Mage::getSingleton(‘core/design_package’)->getPackageName(); // To get the current theme of the Magento store / site Mage::getSingleton(‘core/design_package’)->getTheme(‘frontend’); // You can pass ‘locale’, ‘layout’, ‘template’, ‘default’, or ‘skin’ into the above function. [/php]

Categories
Programming

Magento – Disable Toolbar Sort / Order By Memory Cookie

[xml] <reference name="product_list_toolbar"> <action method="disableParamsMemorizing"/> </reference> [/xml]

Categories
Programming

WordPress – Changing The Site URL Using WP-CLI Command Line Tool

The WP-CLI command line tool isĀ a handy application to run various WordPress tasks. Download the WP-CLI command line tool into the WordPress root folder using CURL or WGET. [bash] curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar [/bash] Check if the tool is working. [bash] php wp-cli.phar –info [/bash] Not run the search and replace command to look through all […]