php - How to use a variable (for wordpress postid) in other queries?

I don't know php, I just edit it for my needs, please excuse my possible mis-use of terms. I think the fact I am se

I don't know php, I just edit it for my needs, please excuse my possible mis-use of terms. I think the fact I am searching for the wrong terms has made this difficult to find a solution for, which is why I am asking.

Basically I need to define a postid, then use it multiple ways.

$number = 455;

So above you can see the number of a postid.

Then within my templates I am using it as follows.

echo get_the_permalink( '$number' );

How do I make that work?

echo get_the_permalink( '455' );

^ works fine, but it means me typing that id a lot.

I don't know php, I just edit it for my needs, please excuse my possible mis-use of terms. I think the fact I am searching for the wrong terms has made this difficult to find a solution for, which is why I am asking.

Basically I need to define a postid, then use it multiple ways.

$number = 455;

So above you can see the number of a postid.

Then within my templates I am using it as follows.

echo get_the_permalink( '$number' );

How do I make that work?

echo get_the_permalink( '455' );

^ works fine, but it means me typing that id a lot.

Share Improve this question asked Aug 13, 2019 at 17:36 TimTim 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

When you use the variable, don't use the quotes. So it would be like:

echo get_the_permalink( $number );

You can also use:

echo get_permalink( $number );

or:

the_permalink( $number )

get_the_permalink() is an alias for get_permalink().

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

相关推荐

  • php - How to use a variable (for wordpress postid) in other queries?

    I don't know php, I just edit it for my needs, please excuse my possible mis-use of terms. I think the fact I am se

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信