全球主机交流论坛

标题: 高分跪求解答一个Worpress插件开发的问题 [打印本页]

作者: Comcast    时间: 2012-8-24 21:24
标题: 高分跪求解答一个Worpress插件开发的问题
我有一个自定义字段叫    MyVar

如何在插件的 自定义函数里使用它?

我直接在插件函数里  get_post_meta     然后echo  无输出。

求解

作者: 360安全卫士    时间: 2012-8-24 21:27
全球WP论坛
作者: edear    时间: 2012-8-24 21:27
http://codex.wordpress.org/Function_Reference/get_post_meta
作者: Comcast    时间: 2012-8-24 21:28
edear 发表于 2012-8-24 21:27
http://codex.wordpress.org/Function_Reference/get_post_meta

直接模板可以 get_post_meta出来但是 在插件自定义函数内不行
作者: edear    时间: 2012-8-24 21:30
Comcast 发表于 2012-8-24 21:28
直接模板可以 get_post_meta出来但是 在插件自定义函数内不行

检查 $post_id 参数
作者: Comcast    时间: 2012-8-24 21:34
edear 发表于 2012-8-24 21:30
检查 $post_id 参数
  1. add_filter( 'the_content',  'test_plugin' );

  2. function test_plugin( $content ) {
  3.         echo "fucking you "; //能输出
  4.         $Field = get_post_meta($post->ID,"Field",true);
  5.         echo $Field; //不能输出
  6. }
复制代码
上面代码是插件里的




欢迎光临 全球主机交流论坛 (https://sunk.eu.org/) Powered by Discuz! X3.4