wordpress - WordPress - 传递 args URL 时出现 404 错误
问题描述
我制作了一个可以正常工作的自定义帖子“项目”,但我需要使用 URL 中的参数过滤项目。
喜欢:mywebsite.com/projects?type_project=wealth
但我每次都会收到 404 错误。
这是 functions.php 中的代码:
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'projets' ) {
// allow the url to alter the query
if( isset($_GET['type_projet']) ) {
$query->set('meta_key', 'type_projet');
$query->set('meta_value', $_GET['type_projet']);
echo($_GET['type_projet']);
}
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
如果我尝试在archive-projects.php 中过滤,它工作正常。 我也尝试过刷新永久链接。
如果有人可以帮助我,请(:
解决方案
推荐阅读
- symfony - 在php控制器中将类型设置为rest url变量
- r - 从应用/映射循环中提取重复索引
- python - 在 python 中安装 SpacCy 语言模型不起作用
- java - Java 8:转换 EnumMap
到地图 - android - Kotlin 不叫 super
- r - 通过改变 R 中的索引创建子列表
- c++ - Arduino IDE 错误 - 无法找到数字文字运算符 'operator""f900ff'
- apache-kafka - Kafka Connect 分布式不工作
- acumatica - 如何在 POReceipt 屏幕中调用 PressCancel
- c - 向 IOT Hub 发布消息 - Eclypse Paho MQTT