URL 参数在多站点上处理不正确
URL parameter is handled incorrectly on multisite
对于通过短代码显示的表单,我们希望将参数添加到 URL,然后在另一个短代码中再次读取它。这些功能是通过自定义插件添加的。
这 在 标准 WordPress 安装 上工作正常 。
但是,如果我们将插件添加到 多站点 安装中,它 不起作用 。以某种方式添加了参数,但出现 'site not found' 错误。随意看看 http://fortbildungen.mgo-fachverlage.de/,我们的多站点安装。
以下是我们的部分代码:
设置参数的简码
这是边栏中的过滤器
function add_shortcode_themen() {
$themen = get_terms( array(
'taxonomy' => 'thema', //Custom Taxonomie 'thema'
'hide_empty' => true,
'parent' => 0,
) );
$arten = get_terms( array(
'taxonomy' => 'art', //Custom Taxonomie 'art'
'hide_empty' => true,
'parent' => 0,
) );
$s = '';
$s .= '<div class="fk-sc">';
$s .= '<form action="" method="GET">';
//### Themen
if( $themen ){
$s .= '<h3>Themenauswahl</h3>';
$themen_gefiltert = Fbk_WPQuery::get_ids('thema');
foreach($themen as $wp_term_object){
$id = $wp_term_object->term_id;
$color = get_term_meta( $id, 'fk-farbe', true );
$slug = $wp_term_object->slug;
$name = $wp_term_object->name;
$s .= '<div style="background-color: ' . $color . '">';
$s .= '<input
type="checkbox"
name="filter_thema[]"
id="fk-sc-' . $slug .'"
value="' . $id . '"';
if(!empty($themen_gefiltert) && in_array($id, $themen_gefiltert)){
$s .= ' checked';
}
$s .= '>';
$s .= '<label for="fk-sc-' . $slug .'">' . $name .'</label>';
$s .= '</div>';
}
echo '</select>';
}
//### Arten
if( $arten ){
$s .= '<br />';
$s .= '<h3>Veranstaltungsart</h3>';
$art_gefiltert = Fbk_WPQuery::get_ids('art');
foreach($arten as $wp_term_object){
$id = $wp_term_object->term_id;
$slug = $wp_term_object->slug;
$name = $wp_term_object->name;
$s .= '<div><input
type="checkbox"
name="filter_art[]"
id="fk-sc-' . $slug .'"
value="' . $id . '"';
if(!empty($art_gefiltert) && in_array($id, $art_gefiltert)){
$s .= ' checked';
}
$s .= '>';
$s .= '<label for="fk-sc-' . $slug .'">' . $name .'</label></div>';
}
}
$s .= '<input type="submit" value="Filtern"/>';
$s .= '</form>';
$s .= '</div>';
return $s;
}
add_shortcode( 'fk-filter', 'add_shortcode_themen' );
获取参数的简码
这是页面内容
add_shortcode( 'fk-kalender', 'add_shortcode_kalender' );
function add_shortcode_kalender() {
$query = new WP_Query(array(
'post_type' => 'fortbildung', //Custom Post Type 'fortbildung'
'post_status' => 'publish',
'tax_query' => Fbk_WPQuery::get_tax_query(), //gets the tax-query from URL-PARAMETERS
'orderby' => 'mgofv_fk_date',
'meta_key' => 'mgofv_fk_date',
'order' => 'ASC',
));
$html .= Fbk_SC_HTML_Builder::get_html_fortbildungen($query); //gets the html for displaying the posts
wp_reset_query();
return $html;
}
还有 class Fbk_WPQuery
class Fbk_WPQuery {
public function get_tax_query(){
$tax_query = array();
if(isset($_GET['filter_thema']) && isset($_GET['filter_art'])){
$tax_query['relation'] = 'AND';
}
if(isset($_GET['filter_thema'])){
$tax_query[] = Fbk_WPQuery::get_thema();
}
if(isset($_GET['filter_art'])){
$tax_query[] = Fbk_WPQuery::get_art();
}
return $tax_query;
}
public function get_thema(){
if(isset($_GET['filter_thema'])){
var_dump($_GET['filter_thema']);
$selected = $_GET['filter_thema'];
$count = count($selected);
$arr = array();
$arr['relation'] = 'OR';
for($i = 0; $i < $count; $i++){
$arr[] = array(
'taxonomy' => 'thema',
'terms' => $selected[$i],
);
}
}
return $arr;
}
public function get_art(){
if(isset($_GET['filter_art'])){
$selected = $_GET['filter_art'];
$count = count($selected);
$arr = array();
$arr['relation'] = 'OR';
for($i = 0; $i < $count; $i++){
$arr[] = array(
'taxonomy' => 'art',
'terms' => $selected[$i],
'operator' => 'AND'
);
}
}
return $arr;
}
public function get_ids($get_param){
if($get_param == "thema"){
if(isset($_GET['filter_thema'])){
$selected = $_GET['filter_thema'];
$count = count($selected);
$id_arr = array();
for($i = 0; $i < $count; $i++){
$id_arr[] = $selected[$i];
}
}
}
else if($get_param == "art"){
if(isset($_GET['filter_art'])){
$selected = $_GET['filter_art'];
$count = count($selected);
$id_arr = array();
for($i = 0; $i < $count; $i++){
$id_arr[] = $selected[$i];
}
}
}
return $id_arr;
}
}
感谢您的帮助:)
努力改变
action=""
至
action="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '"
.
为我工作
对于通过短代码显示的表单,我们希望将参数添加到 URL,然后在另一个短代码中再次读取它。这些功能是通过自定义插件添加的。
这 在 标准 WordPress 安装 上工作正常 。
但是,如果我们将插件添加到 多站点 安装中,它 不起作用 。以某种方式添加了参数,但出现 'site not found' 错误。随意看看 http://fortbildungen.mgo-fachverlage.de/,我们的多站点安装。
以下是我们的部分代码:
设置参数的简码
这是边栏中的过滤器
function add_shortcode_themen() {
$themen = get_terms( array(
'taxonomy' => 'thema', //Custom Taxonomie 'thema'
'hide_empty' => true,
'parent' => 0,
) );
$arten = get_terms( array(
'taxonomy' => 'art', //Custom Taxonomie 'art'
'hide_empty' => true,
'parent' => 0,
) );
$s = '';
$s .= '<div class="fk-sc">';
$s .= '<form action="" method="GET">';
//### Themen
if( $themen ){
$s .= '<h3>Themenauswahl</h3>';
$themen_gefiltert = Fbk_WPQuery::get_ids('thema');
foreach($themen as $wp_term_object){
$id = $wp_term_object->term_id;
$color = get_term_meta( $id, 'fk-farbe', true );
$slug = $wp_term_object->slug;
$name = $wp_term_object->name;
$s .= '<div style="background-color: ' . $color . '">';
$s .= '<input
type="checkbox"
name="filter_thema[]"
id="fk-sc-' . $slug .'"
value="' . $id . '"';
if(!empty($themen_gefiltert) && in_array($id, $themen_gefiltert)){
$s .= ' checked';
}
$s .= '>';
$s .= '<label for="fk-sc-' . $slug .'">' . $name .'</label>';
$s .= '</div>';
}
echo '</select>';
}
//### Arten
if( $arten ){
$s .= '<br />';
$s .= '<h3>Veranstaltungsart</h3>';
$art_gefiltert = Fbk_WPQuery::get_ids('art');
foreach($arten as $wp_term_object){
$id = $wp_term_object->term_id;
$slug = $wp_term_object->slug;
$name = $wp_term_object->name;
$s .= '<div><input
type="checkbox"
name="filter_art[]"
id="fk-sc-' . $slug .'"
value="' . $id . '"';
if(!empty($art_gefiltert) && in_array($id, $art_gefiltert)){
$s .= ' checked';
}
$s .= '>';
$s .= '<label for="fk-sc-' . $slug .'">' . $name .'</label></div>';
}
}
$s .= '<input type="submit" value="Filtern"/>';
$s .= '</form>';
$s .= '</div>';
return $s;
}
add_shortcode( 'fk-filter', 'add_shortcode_themen' );
获取参数的简码
这是页面内容
add_shortcode( 'fk-kalender', 'add_shortcode_kalender' );
function add_shortcode_kalender() {
$query = new WP_Query(array(
'post_type' => 'fortbildung', //Custom Post Type 'fortbildung'
'post_status' => 'publish',
'tax_query' => Fbk_WPQuery::get_tax_query(), //gets the tax-query from URL-PARAMETERS
'orderby' => 'mgofv_fk_date',
'meta_key' => 'mgofv_fk_date',
'order' => 'ASC',
));
$html .= Fbk_SC_HTML_Builder::get_html_fortbildungen($query); //gets the html for displaying the posts
wp_reset_query();
return $html;
}
还有 class Fbk_WPQuery
class Fbk_WPQuery {
public function get_tax_query(){
$tax_query = array();
if(isset($_GET['filter_thema']) && isset($_GET['filter_art'])){
$tax_query['relation'] = 'AND';
}
if(isset($_GET['filter_thema'])){
$tax_query[] = Fbk_WPQuery::get_thema();
}
if(isset($_GET['filter_art'])){
$tax_query[] = Fbk_WPQuery::get_art();
}
return $tax_query;
}
public function get_thema(){
if(isset($_GET['filter_thema'])){
var_dump($_GET['filter_thema']);
$selected = $_GET['filter_thema'];
$count = count($selected);
$arr = array();
$arr['relation'] = 'OR';
for($i = 0; $i < $count; $i++){
$arr[] = array(
'taxonomy' => 'thema',
'terms' => $selected[$i],
);
}
}
return $arr;
}
public function get_art(){
if(isset($_GET['filter_art'])){
$selected = $_GET['filter_art'];
$count = count($selected);
$arr = array();
$arr['relation'] = 'OR';
for($i = 0; $i < $count; $i++){
$arr[] = array(
'taxonomy' => 'art',
'terms' => $selected[$i],
'operator' => 'AND'
);
}
}
return $arr;
}
public function get_ids($get_param){
if($get_param == "thema"){
if(isset($_GET['filter_thema'])){
$selected = $_GET['filter_thema'];
$count = count($selected);
$id_arr = array();
for($i = 0; $i < $count; $i++){
$id_arr[] = $selected[$i];
}
}
}
else if($get_param == "art"){
if(isset($_GET['filter_art'])){
$selected = $_GET['filter_art'];
$count = count($selected);
$id_arr = array();
for($i = 0; $i < $count; $i++){
$id_arr[] = $selected[$i];
}
}
}
return $id_arr;
}
}
感谢您的帮助:)
努力改变
action=""
至
action="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '"
.
为我工作