私はwordpress用のプラグインOOPを作成しています。プラグインは、チームと呼ばれる新しいカスタム投稿タイプを作成します。チームページ内でショートコード[プログラム]を使用して、いくつかのデフォルトのHTMLコードを生成することができます。また、私は新しいメタボックスでカスタムフィールドを作成しました。Wordpress投稿ID
しかし、私はプラグインを呼び出しているページに入っているとき、私はget_post_meta()を取得するために私のプラグイン内に投稿IDを取得する必要があります。
私は次のことを試してみた:
public function __construct(){
// not working
$post;
$post->ID;
// not working
global $wp_query;
$post_id = $wp_query->post->ID;
$post = get_post($post_id);
// not workiing
echo '<pre>';
print_r('post_id:' . get_the_ID());
echo '</pre>';
}
私はフロントエンド(そのプラグインが呼び出され、ショートを実行します)
からページを訪問したとき、私は私のプラグイン内のカスタムポストIDを受け取ることができる方法コンストラクタは のように見えますMyPlugin以内function run_plugin() {
$plugin = new MyPlugin();
$plugin->run();
}
run_plugin();
:
私の主なクラスは、次のようにロードされます
public function __construct() {
if (defined('PLUGIN_NAME_VERSION')) {
$this->version = PLUGIN_NAME_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'MyPlugin';
if(!empty(get_option($this->plugin_name))){
$this->clientID = get_option($this->plugin_name)['client_id'];
}
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
$this->define_shortcodes();
}
私は混乱しています - なぜ2つのコンストラクタがありますか? – FluffyKitten
同じ問題を解決しようとする試みは同じですが、 – Bham