如何在 WordPress 中获取查询字符串 url?
How to get the query string url in WordPress?
我创建了一个自定义 post 模板,根据分类法和术语显示 post。
我创建的 url 看起来像这样:http://example.com/courses/course-title/?type=english-test&term=new
有一个示例 here add_query_arg() 但它似乎是在静态检索值
// This would output '/client/?s=word&foo=bar'
echo esc_url( add_query_arg( 'foo', 'bar' ) );
// This would output '/client/?s=word&foo=bar&baz=tiny'
$arr_params = array( 'foo' => 'bar', 'baz' => 'tiny' );
echo esc_url( add_query_arg( $arr_params ) );
问题: 我怎样才能从 english-test 和 new url 并将它们存储到变量中?
感谢任何帮助。谢谢
您可以检索作为 GET 参数的值。
使用这个:
$variable = $_GET['param_name'];
//Or as you have it
$type = $_GET['type'];
$term = $_GET['term'];
echo $type; // english-test
echo $term; // new
我创建了一个自定义 post 模板,根据分类法和术语显示 post。
我创建的 url 看起来像这样:http://example.com/courses/course-title/?type=english-test&term=new
有一个示例 here add_query_arg() 但它似乎是在静态检索值
// This would output '/client/?s=word&foo=bar'
echo esc_url( add_query_arg( 'foo', 'bar' ) );
// This would output '/client/?s=word&foo=bar&baz=tiny'
$arr_params = array( 'foo' => 'bar', 'baz' => 'tiny' );
echo esc_url( add_query_arg( $arr_params ) );
问题: 我怎样才能从 english-test 和 new url 并将它们存储到变量中?
感谢任何帮助。谢谢
您可以检索作为 GET 参数的值。
使用这个:
$variable = $_GET['param_name'];
//Or as you have it
$type = $_GET['type'];
$term = $_GET['term'];
echo $type; // english-test
echo $term; // new