admin管理员组文章数量:1287803
I've added a Wordpress hook:
add_filter('post_type_link', 'custom_post_type_link_venue', 11, 3);
Everything in that hook prints twice. I've simplified it to its minimum.
function custom_post_type_link_venue ($urlsub2, $post) {
if ($post->post_type == 'product') {
echo "test";
}
}
When I fire that function, "test" is shown twice.
I've added a Wordpress hook:
add_filter('post_type_link', 'custom_post_type_link_venue', 11, 3);
Everything in that hook prints twice. I've simplified it to its minimum.
function custom_post_type_link_venue ($urlsub2, $post) {
if ($post->post_type == 'product') {
echo "test";
}
}
When I fire that function, "test" is shown twice.
Share Improve this question edited Sep 9, 2021 at 14:15 Dennis asked Sep 9, 2021 at 14:02 DennisDennis 1358 bronze badges1 Answer
Reset to default 1When you add a filter to post_type_link
, you are telling WordPress to run the hooked function on the result of the get_post_permalink()
function. So any time that function runs, so does yours.
When I tested the filter myself, I only saw a printed message once for each link, but if you have something like this:
if ( get_permalink() ) {
the_permalink();
}
Then you will see a message printed twice. This is because get_permalink()
calls get_post_permalink()
internally, and so does the_permalink()
. Your custom_post_type_link_venue()
function will run each time.
Since post_type_link
is a filter, not an action, it should only return
a value, and not output anything. If your function does produce any output you may get unexpected results, like you are experiencing.
本文标签: phpWhy does the posttypelink hook everything twice
版权声明:本文标题:php - Why does the post_type_link hook everything twice? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741329583a2372690.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论