permalinks - Return value of get_permalink(0) and get_the_title(0)

I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour.

I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID); works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0) get me to the parent page if I press the button on the parent page? It also gives me the Title even though it would be get_the_title(0)

I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID); works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0) get me to the parent page if I press the button on the parent page? It also gives me the Title even though it would be get_the_title(0)

Share Improve this question asked Aug 23, 2019 at 8:18 RugoRugo 1031 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

If an ID is passed to get_the_title() or get_permalink(), they will use get_post() internally to get a copy of the full post object with that ID. But if get_post() is passed either nothing or a "falsy" value, like 0, then it will return the current global $post object. In the context of your code this is likely to be the current page.

So:

get_permalink( 0 );

Is equivalent to:

get_permalink( get_the_ID() );

Which is equivalent to:

get_permalink();

Because they are all referring to the current global $post.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745222453a4617310.html

相关推荐

  • permalinks - Return value of get_permalink(0) and get_the_title(0)

    I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour.

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信