wordpress - Get the var from url
问题描述
I have url like this:
index.php?category_name=$matches[1]/$matches[2]&var1=yes&paged=$matches[3]
and I want to get var1 from this url, how to do it?
Regards
解决方案
在全局 $wp_query 对象的 WP_Query 类中检索公共查询变量。
用法
<?php get_query_var( $var, $default ) ?>
参数
$var 要检索的变量键。
例子
// Test if the query exists at the URL
if ( get_query_var('var1') ) {
// If so echo the value
echo get_query_var('var1');
}
获取 URL 变量
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['var1'];
推荐阅读
- c++ - QT:在 C++ 中由用户向表中插入数据
- html - 在选择元素之前添加文本
- android - 使用 OmRecorder 在 android 中录制 .wav 格式的文件
- c# - C# 中的 ServiceM8 开发(联系人详细信息和作业同步)
- java - 27.1.x 中的 ViewModel 功能因子活动的配置更改而中断
- jenkins - 如何使用 JUnit Jenkins 插件解析额外的 XML 属性
- jmeter - 如何在 bzm-parallel 控制器中为 https 发布请求提供变量和 CSV 数据?
- jquery - 如何在引导日期分页器中仅显示一项
- android - 将密钥库从 Xamarin 导入 Android Studio
- c++ - SNMP 代理在单元测试期间断开连接