拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 多站点上的URL自变量处理不正确

多站点上的URL自变量处理不正确

白鹭 - 2022-01-23 2110 0 0

对于通过简码显示的表单,我们希望将自变量添加到 URL,然后在另一个简码中再次读取。这些功能是通过自定义插件添加的。

适用标准的 WordPress 安装

但是,如果我们的插件添加到一个多站点安装,它不作业以某种方式添加了自变量,但出现“找不到站点”错误。请随意查看我们的多站点安装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 >';
    $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;
}

和类 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;
    }
}

谢谢你的帮助 :)

uj5u.com热心网友回复:

尝试改变

action=""

action="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '".

为我作业

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *