Внутри функции недоступен get_the_ID() и $post->ID почему, как исправить?
-
Внутри функции fun1 недоступен get_the_ID() и $post->ID почему, как исправить?
Т.е. вызываю шорткод, он вызывает свою функцию, она вызывает третью и вот в ней почему то не получается получить текущий номер поста.
<?php /* Plugin Name: Plugin1 */ class class1 { protected $types; protected $marks; protected $dateUpdate; protected $data; function __construct() { $this->types = array( 'type1' => 'type1', ); $this->marks = array( 'mark1' => 'mark1', ); $this->dateUpdate = get_option('wp-class1-dateUpdate'); $this->data = get_option('wp-class1-data'); if (($this->dateUpdate == 0 && $this->data == 0) || (strtotime(date('Y-m-d')) > $this->dateUpdate)) { $this->updateData(); } add_shortcode('class1', array($this, 'shortcode1')); } function getTypes($string) { foreach ($this->types as $id => $name) { return $id; } } return false; } function getMarks($string) { foreach ($this->marks as $id => $name) { return $id; } } return false; } function fun1($type) { global $post; $resultData = array(); $my_post_id = get_the_ID();///////////!!!!!!!!!//////////// пустое и get_the_ID() и $post->ID; return $resultData; } function getAll() { $resultData = array(); foreach ($this->types as $id => $name) { $resultData[$id] = $this->fun1($id); } return $resultData; } function updateData() { } /** * Создание шорткода function shortcode1($atts) { global $post; extract(shortcode_atts(array( 'type' => 'тип', 'mark' => 'метка' ), $atts)); $my_post_id = $post->ID; $currentType = $this->getTypes($type); $currentMark = $this->getMarks($mark); $data = json_decode($this->data, true); $scope = $data[$currentType][$currentMark]; update_post_meta( $my_post_id, 'horo_dannie', $horoscope); //} return $scope; } } $class1 = new class1;
Просмотр 5 ответов — с 1 по 5 (всего 5)
Просмотр 5 ответов — с 1 по 5 (всего 5)
- Тема «Внутри функции недоступен get_the_ID() и $post->ID почему, как исправить?» закрыта для новых ответов.