$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - What does $temp do?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - What does $temp do?

matteradmin9PV0评论

I am new in WordPress Development. And I saw a sample which uses $temp to store the old $wp_query instance before instantiating a new WP_Query. I guess it is used to return original state when showing some posts other than the current $wp_query contains. But, I would like to be sure and learn other reasons. And I wonder what is the best way of this type of operations.

I am new in WordPress Development. And I saw a sample which uses $temp to store the old $wp_query instance before instantiating a new WP_Query. I guess it is used to return original state when showing some posts other than the current $wp_query contains. But, I would like to be sure and learn other reasons. And I wonder what is the best way of this type of operations.

Share Improve this question edited Mar 10, 2019 at 13:56 Tanmay Patel 8111 gold badge7 silver badges11 bronze badges asked Mar 10, 2019 at 11:25 tafotafo 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

What any variables used in samples do depends entirely on that specific sample. If a sample assigns a query to a variable called $temp, then that's what $temp does. It doesn't mean anything else, it's just what's shown in the sample.

Guide and tutorial writers can and will create and use any variables they want. You will need to read and understand the guide to understand what they're doing, or ask the author if you're unsure. If you need to, learn basic PHP first, as it will help a great deal.

That being said, what you've described — modifying $wp_query directly and then resetting it — is something you should absolutely never do. Do not take further advice from any source that told you to do this.

If you need to query posts for your own purposes, use new WP_Query() or get_posts(), and if you need to modify the main query, use the pre_get_posts filter. These are thoroughly documented across the web, and this site, if you need to know more.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far