Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

php - Wordpress: How to ping URL from custom field on publish

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.

As far as i understand, $add_ping is exactly that. http://codex.wordpress.org/Function_Reference/add_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.

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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');

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...