Categories
Tips & Tricks

Adding Tags Filter to the Posts List

By default, WordPress does not ship the tag filter capability to its posts list whilst, in many cases, we need it to quickly access to the content type we have classified.

To do so, add the following codes:

<?php

/***********************************
* Function to add filter by tags
* in the posts list
*/

function kc_add_taxonomy_filters() {

    global $typenow;

    // an array of all the taxonomyies you want to display. Use the taxonomy name or slug

    $my_taxonomies = array( 'post_tag' );

    switch ( $typenow ) {

        case 'post':

            foreach ( $my_taxonomies as $tax_slug ) {

                $tax_obj = get_taxonomy( $tax_slug );

                $tax_name = $tax_obj->labels->name;

                $terms = get_terms( $tax_slug );

                if ( count( $terms ) > 0 ) {

                    echo "<select name='$tax_slug' id='$tax_slug' class='postform alignleft actions'>";

                    echo "<option value=''>Show All $tax_name</option>";

                    foreach ( $terms as $term ) {

                        echo '<option value="', $term->slug,'" ',selected( @$_GET[$tax_slug] == $term->slug , $current = true, $echo = false ) , '>' , $term->name ,' (' , $term->count ,')</option>';

                    }

                    echo "</select>";

                }

           }

        break;

    }

}

add_action( 'restrict_manage_posts', 'kc_add_taxonomy_filters' );

To your functions.php then you’ll have this filter option right in your posts list:

Add Tag Filter in Posts List

Categories
Tips & Tricks

Check to See Which Ports are Running on Ubuntu Server

There’s a time where we need to check for ports which are running on our current server. To do so, we need to install a software called, nmap. To install, simply run the following command:

$ sudo apt-get install nmap

Then run the following command to see the table of the ports which are currently running on our Ubuntu server:

$ nmap localhost

Categories
Tips & Tricks

Run Composer Install in Mac

First, navigate to the directory you want to run the composer command on. Then paste in the following commands:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Then the directory is executable with any composer command. To run any of the composer commands, simply run:

php composer.phar

Categories
Vesta

Fix: sudo: unable to resolve host

This is happens when we pick the name of fqdn when firstly install Vesta and the name is different from the domain we bought. Then whenever we run the command sudo, we will get such error message.

To avoid showing this annoying message, we need to remove this registered fqdn by going to the /etc and edit the hostname file. Then paste in the following configuration:

127.0.0.1   localhost
127.0.1.1   your-fqdn.sth

Then restart the apache2 service by running this command: sudo service apache2 reload

Categories
Vesta

MySQL Service is not Loaded on Ubuntu 14.04

There is a rare cases happen in one of our client servers which MySQL service could not be loaded based on a number of reasons. We’ve eventually found the solution by going to edit the /etc/mysql/my.cnf and add the following configuration:

open_files_limit=65535

After that restart mysql by running the following command:

sudo /etc/init.d/mysql start

Categories
Vultr

Check if Apache2 and MySQL Services are Running on Ubuntu

To check if Apache2 service is running, simply run the following command:

sudo service apache2 status

To check if MySQL service is running, simply run the following command:

sudo service mysql status

For CentOS or Fedora:

To restart the service: $ sudo systemctl restart httpd

And

To check the service status: $sudo systemctl status httpd
Categories
Vultr

How To Solve NO LANGUAGE DEFINE in Vesta Panel

The solution is to upgrade the hosting plan to a bigger one in Vultr. I don’t understand why it shows such confusing error message.

Categories
Vultr

Creating a Server in Vultr and Installing Vesta Panel

This article will go you through the process of creating a secured VPS cloud hosting on Vultr.

1. Creating a new instance

Login to your Vultr dashboard and buying/creating a new instance.

2. Adding Users

Connecting to the server by using SSH. Using the root account provided by default to connect. For example, ssh root@45.32.11.11 and enter the password provided. Then adding a new user by using the following command:

$ adduser test

After that, adding that new user, test, into the sudo group. To do that, simply run the following command:

$ gpasswd -a test sudo

3. Creating a swapfile

Swapfile enables us to increase the size of the default RAM amount provided by Vultr. It is the reserve file to help allocate when the default RAM space running out. First, paste in the following command:

$ dd if=/dev/zero of=/swapfile count=2048 bs=1M

Next, activate the swapfile by running the following command:

$ chmod 600 /swapfile

Next, tell the server to setup the swap file by running:

$ mkswap /swapfile

Then turn the swapfile on by running the following command:

$ swapon /swapfile

The last step is to enable the swapfile on reboot. First, open up the fstab file by going to

$ nano /etc/fstab

Then paste in the following command, save and quit.

/swapfile none swap sw 0 0

4. Installing Vesta Panel

First run these 2 commands respectively:

$ sudo apt-get update
$ sudo apt-get dist-upgrade

Download Vesta by running the following command:

$ curl -O http://vestacp.com/pub/vst-install.sh

Install Vesta by running:

sudo bash vst-install.sh

5. Install PHP 7 GD Library

In case you have PHP5 Installed, then most of the time, the new running site cannot process the image related actions. That is because of the PHP7 GD library is missing on Ubuntu 14.04–at the time of this writing. To install this library, simply run the following command:

$ sudo apt-get install php7.2-gd

6. Install Soap Extension for PHP 7

Some plugins may require PHP soap extension to work properly. In case the server is using PHP 7, install this extension by running the following command:

$ sudo apt-get install php7.2-soap

Then restart apache.

7. Some Other Missing Modules

For WordPress 5.2 and above, there’s a built-in tool named Site Health under the Tools => Site Health that recommends you to install the missing, might be helpful, other modules on your server.

In my case, WordPress recommends me to install bcmath and imagick modules to improve the site performance.

$ sudo apt-get install php7.2-bcmath

$ sudo apt-get install php7.2-imagick

Then restart apache.

I’ve shot a video following the above step by step guides. But unfortunately the video was made in Khmer language, I’ll add English subtitle later on.

Watch the Video:

Categories
CAMWP DEV

CAMWP DEV Library is Back

As of 29 March 2017, CAMWP DEV Library blog has been up and running again due to the Vultr’s unexpected error occur a few days ago.

Unfortunately, all of the previous posts are lost together with the broken instance we deleted.

However, we still hope that this Library blog will still provide us all the valuable tips and tricks in various web and mobile development world.