Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of setting get_term_link parameters of function in WordPress

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to set the get_term_link parameter of the function in WordPress, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's go to know it together.

How to set the parameters of the function get_term_link in WordPress?

Parameter setting of function get_term_link in WordPress

Recently, to help a friend write an enterprise theme, I need to set a special post type called product for the product. In order to manage the convenience, I set up a special classification type and label type for product, which is product_cat (the classification type of WordPress itself is category).

Why use get_term_link?:?

The new type of classification cannot link the address with the output classification, you need to use the get_term_link () function, which is used as follows:

Refer to WordPress Codex: http://codex.wordpress.org/Function_Reference/get_term_link for more information

Question:

For example:

-the variable of the custom classification ID is $term,$term, which is changed according to the background setting. For convenience, the background parameter is assumed to be $custom_term = 8.

-I want to obtain the category link address with a custom category ID of $term. According to the official instructions, it should be:

It seems to be true, but here comes the problem, which returns an error:

Catchable fatal error: Object of class WP_Error could not be converted to string in. . Yes, directly using echo $term; to output the result is indeed 8, which is depressing.

But if you just do this:

It's working again.

Solution:

When WordPress Codex was spinning around, he accidentally saw that foreign friends also encountered this problem, and then he solved it himself, an epiphany. Portal. "

The original variable type problem, this get_term_link function and other commonly used WordPress functions are different, will not convert their own variable types, you have to convert the character class to integers in order to work properly, good Orz function!

Here's how it works:

(Bolo sitting on the sofa Note: intval ($term, 10) will be better, otherwise there will be a binary conversion problem when the $term value is too large, or use (int) $term)

Therefore, in the future, when you encounter a function like this, you have to consider whether it is a variable data type problem.

Play around (end).

The above is all the contents of the method of setting the get_term_link parameter of the function in WordPress. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report