對于通過簡碼顯示的表單,我們希望將引數添加到 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'] . '".
為我作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/405238.html
標籤:
上一篇:陣列索引的if條件
