WordPress的更新后的元当上的超链接

问题描述:

用户点击我试图更新后的元键时从WordPress博客的前端的链接用户点击。我真正想要的是在dealexp_expired_status键更新为“开”,当用户点击链接的价值。WordPress的更新后的元当上的超链接

任何想法如何实现?谢谢!

UPDATE:这里是我的代码至今:

add_filter('the_content', 'my_the_content_filter', 20); 

function my_the_content_filter($content) { 
$content = dealexp_add_exp_link() . $content; 

// Returns the content. 
return $content; 
} 

function dealexp_add_exp_link() { 
$exp_url = plugins_url('/deal-expirator/includes/update.php'); 
?> 
<a href="<?php echo $exp_url; ?>?update_key=1">Mark Expired</a> 
<?php } 

而在update.php文件,我有:

<?php 

if (isset($_GET["update_key"])) { 
global $post; 
update_post_meta($post->ID, 'dealexp_expired_status', 'on'); 
} 

?> 

但是,我得到一个致命错误当点击链接时。任何想法或建议?

  1. 用新参数创建超链接。例如的index.php?update_key = 1

  2. 在需要PHP文件创建php块。

例如,如果你正在做它在single.php中粘贴内while (have_posts())块这样的代码:

<?php if (isset($_GET["update_key"])) {update_post_meta($post->ID, 'dealexp_expired_status', 'key_value');} ?> 
+0

谢谢!我想,虽然与WordPress的内容过滤器使用它,需要每一个环节,以更新各个帖子。为了澄清,我试图用这个创建一个插件。 – Mitchell

+0

我刚刚更新了原来的职位,包括我现在所拥有的代码。你能看看我做错了什么,会产生一个致命的错误吗?谢谢! – Mitchell

+0

我在哪里可以看到你的代码? –