Project Management, WordPress

Time ago implementation in WordPress

Time ago can be implemented in the WordPress Posts using get_the_time() and human_time_diff() functions.

$postedTime = get_the_time(‘U’,$post->ID);
get_the_time() function retrieves the time at which the post was written.

human_time_diff( int $from, int $to ), determines the difference between two timestamps by providing the posted date of the post and current time.

$timeAgo = human_time_diff($postedTime ,current_time( ‘U’ ));

Example in a WP loop :

Click to learn more about get_the_time() and human_time_diff() functions in codex.

Hits: 2

ACF, Filter and Hooks, Programming, WordPress

Saving the CF7 submission in the Dashboard using ACF

1. First, create an acf options page. I am creating Cf7 Submissions as my option page where I will list all my form submissions values

2. Create a form using CF7. I am using the default form cf7 provides

3. Create a repeater field in acf to save the form submitted values in the database and assign it to Cf7 Submissions options page

4. CF7 provides hook wpcf7_before_send_mail which enable us to process the  submiited data the way we like before submitting the form. I am using this hook to save the form submission in the dashboard

5. update_field updates the values in the database
We are capturing the previously submitted data, so that we could merge it with the new submitted form values .

Note : The previously saved data’s in the repeater fields are lost if we don’t merge and update it with the new data’s submitted by the form

6.  Check the cf7 submission options page to see the lists of saved submitted form fields in the dashboard


Hits: 8

Programming, WordPress

PHP code to Import the taxonomy terms from one website to another

1. Create a folder in the root directory of the site i.e PARENT_SITE from where we want to export the Taxonomy Terms. I have created services folder in the root directory and created the php file named books-category.php

2. Include wp-load.php the files so that we could use all the WordPress available functions

3. Write a code that echo’ s JSON representation of a terms related to book taxonomy . We can replace the taxonomy name by any other taxonomy we want to import


We can check the encoded taxonomy terms in the Url : http://PARENT_SITE/services/books-category.php

4. Create a folder in the root directory of the site I call it as CHILD_SITE where we want to import the Taxonomy Terms.

I have created app folder in the root directory of CHILD_SITE and created the php file named import-books-taxonomy.php :

5. Create a two meta field to store the parent id and the id of taxonomy terms OF the PARENT_SITE in the same taxonomy of CHILD_SITE .

We can use acf to create the meta/custom field in the taxonomy :

6. We can Use Guzzle to parse the json response from the MAIN_SITE :

7. Write a code to read the JSON formated terms and insert terms in database

8. When imported, term is inserted in the database of the CHILD_SITE, the id of the inserted term is different than the PARENT_SITE term id . Therefore, PARENT_SITE term_id and parent_id of terms are saved in the CHILD_SITE of related taxonomy terms, so that it could be usedful in the future.

9. Run File to import the taxonomy terms, http://CHILD_SITE/app/books-category.php

Hits: 6


Filter to add new css class to li elements

Most of us are familiar with adding class from the dashboard that follows :

1. In Appearance > Menus, click the screen Option Tab

2. Under Show advanced menu properties, check CSS Classes

3. Expand any menu item to see the css class text input field

4. Enter desired class name and save menu to apply the class to the menu item

If you are searching for an option to get rid of editing each menu items to add same custom class to all in the menu items, you can go for filter


  • $classes is an array of the CSS classes that are applied to the menu item’s element,
  • $item is the current menu item,
  • $args is an object of wp_nav_menu() arguments,
  • $depth is Depth of menu item

To learn more about the filter, please can refer the codex.

Hits: 6

Programming, WordPress

Fix Fatal error: Maximum execution time of 30 seconds exceeded

In WordPress, maximum execution time fatal error is seen when trying to update theme or plugins. Usually the problem occurs when a code takes a long time to run and reaches the maximum time limit set in the hosting server.

To fix the error,

1. Find your .htaccess file in the root directory, add the below line of code at the bottom of your .htaccess file and save it. The code sets the maximum execution time to 300 secs .

After saving the .htaccess file, check if the error still exists. If this doesn’t fix the issue, check the issue by increasing the maximum execution time to 600 secs

2. Create a php.ini file inside your WordPress root folder , add the following line in the php.ini file and save it.

Check your website to see if the error has gone.

3. If both of the aforementioned methods don’t fix the issue, contact your hoster for assistance.

Hits: 14