问题描述
我做了一个自定义的“项目”帖子,效果很好,但是我需要使用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,效果很好。 我也尝试过刷新永久链接。
如果有人可以帮助我,请(:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)