set_query_var() - WordPress 函数参考中文文档

返回介绍

set_query_var()

发布于 2017-09-11 字数1931 浏览 922 评论 0

set_query_var( string $var,  mixed $value )

Set query variable.


描述


参数

$var

(string)
(Required)
Query variable key.

$value

(mixed)
(Required)
Query variable value.


源代码

File: wp-includes/query.php

function set_query_var( $var, $value ) {
	global $wp_query;
	$wp_query->set( $var, $value );
}

更新日志

Version 描述
2.2.0 Introduced.

相关函数

Uses

  • wp-includes/class-wp-query.php:
    WP_Query::set()

Used By

  • wp-includes/comment-template.php:
    wp_list_comments()
  • wp-includes/comment-template.php:
    comments_template()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by stode

    One use case for this is to pass variable to template file when calling it with get_template_part().

    
    // When calling a template with get_template_part()
    set_query_var('my_form_id', 23);
    get_template_part('my-form-template');
    

    Now in you template you can then call it.

    
    // Inside my-form-template.php
    $my_form_id = get_query_var('my_form_id');
    

上一篇:set_post_type()

下一篇:set_screen_options()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!