Tag Archives: Wordpress

[SOLVED] WooCommerce conditional fields for gifts options on checkout

Built a web site recently using WooCommerce and decided that a gift wrapping option would be wonderful idea when user checks out.

However, the WooCommerce Checkout Add-Ons plugin whilst its great, is still in its infancy and on the checkout page, it simply populates the page with all the add ons, so makes the checkout page look HUGE!

My idea, was to add a checkbox asking the user if they wanted to gift wrap the order and then when checked, a list of the options would appear.

 

[Solved] Get Array of Terms for Custom Post Type Outside of Loop with Post ID

Every stone I overturned looking for the answer to this issue I was met with “use wp_get_post_terms()” but unfortunately it does not work on custom post types.

The solution, after much digging and experimenting is to use get_the_term_list() but with a couple of twists.

Now, I have a custom post type called “faq”.

To get the “terms” or “tags” for the “faq” post type you need to know what the “taxonomy name” is. In this case, the taxonomy name is “faqs-tags”.

To find out the taxonomy name for the custom post type, check the screenshot below. Easy!

[SOLVED] Add a Custom Column in Custom Post Types Admin Screen Displaying Relational Data From Another Custom Post Type

I had a situation recently with WordPress where I had to display the Company Name against the Attendee profile when viewing a list of Attendees inside the WordPress admin.

Basically there was two custom post types (CPT’s), one was called “attendee” and the other “companies”. When editing an Attendee record we would assign it to a company so that we knew which Company the Attendee was assigned to.

After some ideas from the Advanced WordPress forum on Facebook, this is what I ended up with and code is included below.

custom-column-in-custom-post-type-admin-screen

Here is the code which I inserted into the themes functions.php to display the company name against the attendee record.

[SOLVED] Using mysql_query in WordPress After PHP 5.5

Okay, I am a bit old skool and still use mysql_* and yes I can hear some of you sighing, face palming yourselves and rolling your eyes but I have built thousands of sites over the years, many of you were in diapers when I started and I guess I have been a little slow on the uptake as my code has always been secure and solid, however, yes I realise I need to stop using it because as of PHP 7 it will be removed completely (apparently).

My hope is that this post will help some poor soul, who like me has wasted hours of precious family or personal time trying to resolve the issue.

Annnnnnyway, so, last night I upgraded the PHP version on one of my sites from 5.1 to 5.5 and visited one of the WordPress sites on the server and could see anywhere we have used mysql_query, it was showing the following error:

Warning: mysql_query(): Access denied for user ”@’localhost’ (using password: NO) in/home/website/public_html/wordpress/wp-content/themes/ourtheme/custom/programmes/template1.php on line 4

Warning: mysql_query(): A link to the server could not be established in/home/website/public_html/wordpress/wp-content/themes/ourtheme/custom/programmes/template1.php on line 4
Access denied for user ”@’localhost’ (using password: NO)

I literally spent hours last night trying to find the root cause, I even got the official Cpanel Support team involved thinking it was an issue with PHP on Cpanel or maybe permissions on mysql were fuddled. After a few goes, even the cpanel guy gave up and said it had to be wordpress.

This morning I have come back with a fresh head and searched the google for about 45 minutes and stumbled upon a post (by 1and1 nonetheless…who would have guessed eh?) which suggested to add the following line to your wp-config.php file if you are still using mysql_query() on PHP 5.5

So I added that line to the wp-config.php and all the errors cleared up and the site is rocking on as usual.

You see, WordPress has stopped supporting mysql_* with PHP 5.5, even though PHP 5.5 still supports it, so in essence this was WordPress putting its foot down saying “hey you old dog! stop using non standard ways to connect to the wordpress database”.

Lesson learned and now off to start adapting code to more modern standards such as PDO and MYSQLi.

UPDATED 8/2/2017 – For some of the bigger sites, I will need to use MYSQL SHIM becaseu in some cases its simply not practical to recode everything..

Hiding Part of a WordPress Template Based on the Type of Template Being Used

Here is a nifty piece of code you can use in the case you need to hide something or show something on a wordpress template that you have assigned to your page.

So in the instance you needed to hide the navigation menu on a certain type of page within your site you would literally add a few lines of code as the wordpress codex already provides a function for determining if the page is using a certain type of template. (see: is_page_template )

Lets assume the following.

  1. You have made a wordpress template called “template-no-nav.php” inside the theme root
  2. You have assigned your page the custom template
  3. You want to hide the navigation menu from the template

Just add the following code to the header.php file where your navigation menu would normally appear.

1
[crayon-5c1304c012bd3571926621/]

[solved] .htaccess not working in wordpress sub directory

Today, one of my clients mentioned that his rest api was not working and was returning 404 errors and the iphone app was broken due to the 404 errors.

As he is running wordpress the immediate thought was that wordpress was overriding something and showing 404 errors inside his api directory (usually 404 errors indicate that the folder/file does not exist but we checked and the folder was there).

Here is a visual example of the issue.

When i opened up his .htaccess file in his /api/ directory I could see the following which is pretty standard .htaccess format.

1


		

I noticed that the rewrite base was not being defined and this usually occurs when you have an apache server configured for “AllowOverride None” so I added another line to his .htaccess file to get it working again (see line 4 below RewriteBase /api/).

1


		

I hope this helps those who also had this issue.

Set up WordPress Database Connection for Dev Server and Live Server

If you are developing wordpress sites then more than likely you will be setting up a local dev version using something like MAMP PRO and then staging the development on your live production server at your web host.

By far the most easiest way I have found to accomplish auto switching between dev connection and live connection is to do the following.

  1. make two copies of your wp-config.php
  2. rename one of them wp-config-live.php
  3. rename the other file wp-config-dev.php
  4. open the original wp-config.php file and delete everything and drop in the following code

All you have to do then is edit the dev server name in wp-config.php, then just update the test and live config files and you are done.

Job Done! Now you have two separate config files for each server you are running.

{code type=php}

{/code}

5 Great Things About WordPress

WordPress is an Open Source project dedicated to make online writing and publishing easier and accessible to everyone. Being an Open Source project, creating and maintaining WordPress depends on hundreds of people around the globe who work on the project for free. The creators are proud to say that WordPress is a creation for the community by the community.

WordPress.org
WordPress is licensed under the General Public License (GPL) allowing anyone to use it for anything, free of charge. The only investment you need is time and some basic system requirements to make sure that the software works after installing.

WordPress.com
WordPress is not exclusive to technically advanced people. The creation of WordPress.com allows anyone with Internet access to publish a WordPress software-based blog in no time, also for free. However, there are some functional limitations to a WordPress.com blog.

With enough knowledge, you can add WordPress to your online marketing mix. Below are 5 reasons why WordPress is cool enough to stay online for a long time.

1. Accessibility
The low-barrier entry that comes with WordPress is a delight for any online user. Usually, open source software is only made accessible to developers who are working on the software or beta testers who look for bugs. In this case, WordPress software and blog may be used and viewed by the public.

2. May be accessed by search engines
Online marketing solutions providers often have problems dealing with a client’s Content Management System (CMS). Unlike WordPress, most CMSs used by commercial websites make it difficult for search engines to crawl through the pages, rendering SEO efforts useless.

3. Supports plug and play
The WordPress structure welcomes customizations. And because WordPress is all about making online publishing easy for everyone, it accommodates plugins that are easy to install, maintain, and use. Developers and enthusiasts all over the world can contribute their plugins. WordPress users have a comprehensive menu of customizations to choose from, ranging from improving SEO techniques to embedding media files.

4. Themes galore
WordPress has supported a wide array of themes since version 1.5. Random people who are capable of web design have contributed to the growing number of templates for the consumption of anyone who uses WordPress.

Besides a delightful selection of professional and creative themes, WordPress assures that themes are detached from all content. Changing themes won’t put your content at risk of being deleted.

5. Unity in diversity
The structure with which WordPress is created makes it sustainable. There are 3 independent pocket organisations responsible for keeping WordPress running:

• WordPress engine
Comparable to the nervous system in human beings, the WordPress engine embodies the Open Source project per se. Driven by the simple mission of creating the best software, individuals who compose the WordPress engine create the code by which WordPress functions.

• WordPress Themes
Independent individuals contribute to the thousands of themes available for anyone to use. These people probably know nothing of the codes. This is why you can do as you please with the templates without jeopardising your data published through WordPress.

• WordPress Plugins
Other independent developers interested in adding customizable functions contribute to the huge number of plugins for WordPress. These people have no ties with WordPress engine or WordPress themes, such that failure to update your plugin won’t result to data loss.

This 3-branch structure allows WordPress to transcend mandates on upgrades that could hold your entire online publication hostage. An entire community pitches in to make WordPress better for everyone.