Reputation: 13
With a form that is displayed via a shortcode, we want to add parameters to the URL and then read it out again in another shortcode. These functionalities are added via a custom plugin.
This works fine on a standard WordPress installation.
However, if we add the plugin to a multisite installation, it does not work. The parameters are added somehow, but an 'site not found' error occurs. Feel free to have a look at http://fortbildungen.mgo-fachverlage.de/, our multisite installation.
Here are parts of our code:
Shortcode that sets the parameters
This is the filter in the sidebar
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' );
Shortcode that gets the parameters
This is the content of the page
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;
}
And the 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;
}
}
Thanks for any help :)
Upvotes: 1
Views: 102
Reputation: 26
try to change
action=""
to
action="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '"
.
Worked for me
Upvotes: 1