Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...