Category Archives: PHP

How to Limit the Number of Archive Months Displayed in WordPress

If you want to display the number of archive months in WordPress then you just need to add the below function in functions.php file of your current active theme.

After adding the below function in functions.php use the shortcode in WordPress text editor or text widget. This will display archives list with limited months which you will set in the below function.


// Function to get archives list with limited months
function wpb_limit_archives() { 
 
$my_archives = wp_get_archives(array(
    'type'=>'monthly', 
    'limit'=>12,
    'echo'=>0
));
     
return $my_archives; 
 
} 
 
// Create a shortcode
add_shortcode('w3m_custom_archives', 'w3m_limit_archives'); 
 
// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode');

Revolution Slider isn’t working on PHP 7.2 – WordPress

Hello Friends.
Now a days we all know that PHP 7.2 has been released and PHP 5.6 or older version will no longer receive any security updates or bug fixes. So it’s mandatory to upgrade our PHP Or WordPress websites on PHP 7.2 ASAP.

While upgrading the WordPress site on PHP 7.2 I just noticed that the plugin “Revolution Slider” has stopped working and it’s breaking the site. So after researching on this I found the solution as mentioned below.

Step 1: edit file db.class.php

Using SFTP, WordPress Plugin Editor or a file manager (cPanel/Plesk) edit /wp-content/plugins/revslider/inc_php/framework/db.class.php

Find the below code:


  private function checkForErrors($prefix = ""){
  if(mysql_error()){
    $query = $this->wpdb->last_query;
    $message = $this->wpdb->last_error;

    if($prefix) $message = $prefix.' - '.$message.'';
    if($query) $message .=  '--- Query: ' . $query;

      $this->throwError($message);
    }
  }

Replace it with this code:


private function checkForErrors($prefix = ""){
  if(function_exists('mysql_error')){
    if(mysql_error()){
      $query = $this->wpdb->last_query;
      $message = $this->wpdb->last_error;
      if($prefix) $message = $prefix.' - '.$message.'';
      if($query) $message .=  '--- Query: ' . $query;
      $this->throwError($message);
    }
  }
}

Step 2: edit file base_admin.class.php

Using your opted file editor, edit file /wp-content/plugins/revslider/inc_php/framework/base_admin.class.php

Find the below code:


private static $arrMetaBoxes = ""; //option boxes that will be added to post

Replace it with this code:


private static $arrMetaBoxes = array();

That’s it 🙂