Else condition in template file creating fatal error in plugin file

This is my code for template file which is created for custom post type.

if( isset( $_GET['req_edit'] ) && is_numeric( $_GET['req_edit'] ) ){
    --some code---
 }else{ 
 --some code---
    }

There is huge amount of code in that if else but I only posted that much. Because when I comment else condition it’s fine but when I dont comment else then it create fatal error in plugin file. This is error.

Read More
Fatal error: Call to a member function get_results() on a non-object in
   /home6/plotsup1/public_html/plotsup_plot/wp
 -content/plugins/revslider/inc_php/framework/db.class.php on line 125 

What would be the possible reason behind this??
This is my code in else

 else {



$action                         =   'view';
$submit_title                   =   ''; 
$submit_description             =   ''; 
$prop_category                  =   ''; 
$property_address               =   ''; 
$property_county                =   ''; 
$property_state                 =   ''; 
$property_zip                   =   ''; 
$country_selected               =   ''; 

$property_status                =   '';

$property_price                 =   ''; 
$property_label                 =   '';   
$property_size                  =   ''; 
$property_lot_size              =   ''; 

$property_rooms                 =   ''; 
$property_bedrooms              =   ''; 
$property_bathrooms             =   ''; 

$option_video                   =   '';
$option_slider                  =   '';
$video_type                     =   '';  
$embed_video_id                 =   ''; 
$property_latitude              =   ''; 
$property_longitude             =   '';  
$google_view                    =   ''; 
$prop_featured                  =   '';
$google_camera_angle            =   ''; 
$prop_category                  =   '';   

$wpdb                           =   '';
$firm_name                      =   '';
$prop_stat                      =   '';
$monthly_rent                   =   '';
$maintainance                   =   '';
$owner_ratio                    =   '';
$developer_ratio                =   '';
$deposit                        =   '';
$property_status                =   '';
$state                          =   '';
$district                       =   '';

$taluka                         =   '';
$landmark                       =   '';
$req_frontage                   =   '';
$property_deal                  =   '';
$req_reason                     =   '';
$docid                          =   '';
$req_ownership                  =   '';
$nakashaid                      =   '';        
$property_rate                  =   '';
$land_area_from                 =   '';
$land_area_to                   =   '';
$req_document                   =   '';
$req_location                   =   '';
$req_distance                   =   '';
$budget_from                    =   '';
$budget_to                      =   '';
$purchase                       =   '';
$req_access                     =   '';
$req_facing                     =   '';
$electricity                    =   '';
$water                          =   '';
$drainage                       =   '';
$boundry                        =   '';

$edit_id='';
$custom_fields = get_option( 'wp_estate_custom_fields', true);    
$custom_fields_array=array();
$i=0;

if( !empty($custom_fields) ){
    while($i< count($custom_fields) ){
       $name =   $custom_fields[$i][0];
       $type =   $custom_fields[$i][2];
       $slug =   str_replace(' ','_',$name);
       $custom_fields_array[$slug]='';
       $i++;
    }
}







foreach ($status_values_array as $key=>$value) {
    $value = trim($value);
    $value_wpml=$value;
    $slug_status=sanitize_title($value);
    if (function_exists('icl_translate') ){
        $value_wpml= 
 icl_translate('wpestate','wp_estate_property_status_front_'.$slug_status,$value );
    }

    $property_status.='<option value="' . $value . '"';
    if ($value == $prop_stat) {
        $property_status.='selected="selected"';
    }
    $property_status.='>' . $value_wpml . '</option>';
 }

 $video_values                   =   array('vimeo', 'youtube');
 foreach ($video_values as $value) {
  $option_video.='<option value="' . $value . '"';
  $option_video.='>' . $value . '</option>';
 }   



 $option_slider='';
 $slider_values = array('full top slider', 'small slider');
 $slider_type = get_post_meta($edit_id, 'prop_slider_type', true);

 foreach ($slider_values as $value) {
    $label_slider=$value;
    $slug_slider=sanitize_title($value);
    if(function_exists('icl_translate')){
         $label_slider=  icl_translate('wpestate','wp_estate_property_slider'.$slug_slider,
 $value );
    }

    $option_slider.='<option value="' . $value . '"';
    if ($value == $slider_type) {
        $option_slider.='selected="selected"';
    }
    $option_slider.='>' . $label_slider . '</option>';
 }

 }

Related posts

Leave a Reply

1 comment

  1. The error is caused due to the improper declaration. You must declare the $wpdb variable as global. ie:

    global $wpdb;
    

    Likewise if there are any other variables that should be declared, you have to do it.