返回数据库时未定义的索引导致Codeigniter

I am trying to transfer data over from a Wordpress database into a Codeigniter project. I have a model method that returns a single value, but I keep getting the following:

Message: Undefined index: meta_value

Filename: models/transfer_model.php

Here's the model:

 public function get_meta($post_id, $key)
    {
        $this->db->select('meta_value');
        $this->db->from('wp_postmeta');
        $this->db->where('post_id', $post_id);
        $this->db->where('meta_key', $key);
        $this->db->limit(1);

        $query = $this->db->get();

        $row = $query->row_array();

        return $row['meta_value'];
    }

If I print_r($row);, I get the following:

Array
(
    [meta_value] => The Data
)

How can I stop it from returning this error?

where there record fetched you are getting return when there is no record fetched with query then there will be nothing means your row is empty to avoid this use key_exists or array_key_exists have look on php doc

array_key_exists

public function get_meta($post_id, $key)
    {
        $this->db->select('meta_value');
        $this->db->from('wp_postmeta');
        $this->db->where('post_id', $post_id);
        $this->db->where('meta_key', $key);
        $this->db->limit(1);

        $query = $this->db->get();

        $row = $query->row_array();

        $return = '';
        if(key_exists('meta_value',$row))
         $return = $row['meta_value'];

        return $return;
    }

What if you use an integer index?

$row = $query->row_array();
return $row[0];