Wordpress:如何在发布时从自定义字段ping URL [英] Wordpress: How to ping URL from custom field on publish

查看:108
本文介绍了Wordpress:如何在发布时从自定义字段ping URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于源链接的自定义字段.帖子发布后,应该对在此自定义字段中插入的URL进行ping操作.我知道有一个专用的引用字段,但是我想自动添加自定义字段中的URL.

i have a custom field for source-links. The URL inserted in this custom field should get pinged once the post gets published. I know there is a dedicated trackback field but i want the URL from the custom field automatically added.

据我了解,$ add_ping就是这样. http://codex.wordpress.org/Function_Reference/add_ping

As far as i understand, $add_ping is exactly that. http://codex.wordpress.org/Function_Reference/add_ping

我的问题是:我不知道在哪里添加它.我想如果将它写到显示源链接的主题中,则每次访问该帖子时都会对源进行ping操作.

My problem is: i don't know where to add it. I imagine if i'd write this into my theme where i display the source-link, the source gets pinged everytime the post gets visited.

那么添加url以在发布时ping通的正确方法是什么?

So whats the proper way to add an url to get pinged on publish?

要清楚:这不是我想要ping的服务.更像是在B的内容中插入将B的链接.帖子A发布后,帖子B(或其博客)便会被ping通.我想将链接插入帖子A的自定义字段中,而不是其内容区域中.

To be clear: it is not a service that i want to get pinged. More like if you'd insert a link to post B into post A's content. Once post A gets published, post B (or its blog) gets pinged. I want to insert the link into a custom field of post A, instead of its content area.

推荐答案

我认为Felipe是正确的.您可以尝试这样的事情:

I think Felipe is right. You could try something like this:

function doCustomPing ($post_id) {
    $uri_to_ping = get_post_meta($post_id, 'FIELDNAME', true);
    add_ping($post_id, $uri_to_ping);
}

add_action ('publish_post', 'doCustomPing');

因此,每当发布一个帖子(包括其编辑过的帖子)时,到publish_post的钩子都将运行doCustomPing函数.如果您将其作为主题的一部分,请将上面的代码放在您的functions.php文件中.如果您的自定义字段的名称为FIELDNAME,则输入该名称.

So every time a post if published (that includes if its edited) then a hook into publish_post will run the doCustomPing function. If you're putting this as part of a theme drop the above code in your functions.php file. Put the name if your custom field where it says FIELDNAME.

这篇关于Wordpress:如何在发布时从自定义字段ping URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆