Beispiel #1
0
 /**
  * Magic method to return the meta data like the user original fields.
  *
  * @param string $key
  *
  * @return string
  */
 public function __get($key)
 {
     if ($value = parent::__get($key)) {
         return $value;
     }
     if (!isset($this->{$key})) {
         if (isset($this->meta->{$key})) {
             return $this->meta->{$key};
         }
     }
 }
Beispiel #2
0
 /**
  * Magic method to return the meta data like the post original fields.
  *
  * @param string $key
  *
  * @return string
  */
 public function __get($key)
 {
     if (($value = parent::__get($key)) !== null) {
         return $value;
     }
     if (!property_exists($this, $key)) {
         if (property_exists($this, $this->primaryKey) && isset($this->meta->{$key})) {
             return $this->meta->{$key};
         }
     } elseif (isset($this->{$key}) and empty($this->{$key})) {
         // fix for menu items when chosing category to show
         if (in_array($key, ['post_title', 'post_name'])) {
             $type = $this->meta->_menu_item_object;
             $taxonomy = null;
             // Support certain types of meta objects
             if ($type == 'category') {
                 $taxonomy = $this->meta()->where('meta_key', '_menu_item_object_id')->first()->taxonomy('meta_value')->first();
             } elseif ($type == 'post_tag') {
                 $taxonomy = $this->meta()->where('meta_key', '_menu_item_object_id')->first()->taxonomy('meta_value')->first();
             } elseif ($type == 'post') {
                 $post = $this->meta()->where('meta_key', '_menu_item_object_id')->first()->post(true)->first();
                 return $post->{$key};
             }
             if (isset($taxonomy) && $taxonomy->exists) {
                 if ($key == 'post_title') {
                     return $taxonomy->name;
                 } elseif ($key == 'post_name') {
                     return $taxonomy->slug;
                 }
             }
         }
     }
 }