I have some issues with add/delete taxonomy from url.
$arch_postID - i get posts ID's from loop on current archive page.
How it works:
1 - when i push <a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a>
i'm aditing to page URL appropriate '+slug'
2 - When i push <a href="'. $linkk .'" >-</a>
i'm removing appropriate '+slug' from current url( if it's exist )
Now code working like that:
I have 3 slugs to add, "other-1", "other-2", "other-3". I add them one by one, first- "other-1", last- "other-3"
Current URL be like - "domain/other/other-1+other-2+other-3"
When im trying to push "-" on slug "other-1" i get back whole current URL
When im pushing "-" on slug "other-2" i get URL - "domain/other/other-1". But not URL - "domain/other/other-1+other-3"
When im pushng "-" on "other-3" i get right back value. URL - "domain/other/other-1+other-2"
Some one, Help pls! Thanks for your time!
$Path=$_SERVER['REQUEST_URI'];
$Prev_path=$_SERVER['HTTP_REFERER'];
$URI='http://gradrich.tmweb.ru'.$Path;
global $arch_postID;
if ( !empty($arch_postID) && is_archive() ){
for($i = 0; $i <= $b-1; $i++){ //goes a 100 time from 0, to show all parameters from wp_get_post_terms array
$terms_array = wp_get_post_terms($arch_postID[$i],'other');
for($a = 0; $a <= 100; $a++){
$terms_name[] = $terms_array[$a]->name; // create array of terms->name
$terms_slug[] = $terms_array[$a]->slug; // create array of terms->slug
}
}
$result_name = array_unique($terms_name); // check name array for unique variables
$result_slug = array_unique($terms_slug); // check slug array for unique variables
for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){ // do loop for all unique variables
if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){//check if variables not empty than get proper name and slug from two arrays
$res_slug[$f] = '+'.$result_slug[$s].'';
$linkk[$f] = substr($URI, 0, strrpos($URI, $res_slug[$f]));
echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a>';
echo '<a href="'. get_post_type_archive_link() .''. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
echo '<a href="'. $linkk .'" >-</a></div>';
if (false !== strpos($Path, $result_slug[$s])) {
echo '<style>#cat-hide-'. $s .'{display:none;}</style>';
echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>';
echo '<a href="'. get_post_type_archive_link() .''. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
echo '<a href="'. $linkk[$f] .'" >-</a></div>';
}
} else{
}
}
}
I find solution, what was used to devide current URL for finding added tags->slug, delete it and get new URL:
$only_tags = substr($URI, strrpos($URI,'/')+1);
$tags = explode('+',$only_tags);
$tags_string = implode('+',$tags);
Working code below:
for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){
if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){
$only_tags = substr($URI, strrpos($URI,'/')+1);
$tags = explode('+',$only_tags);
foreach ($tags as $t_key=>$t_value) {
if ($t_value == $result_slug[$s]) unset ($tags[$t_key]);
}
$tags_string = implode('+',$tags);
echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .'+'. $result_slug[$s] .'" >+</a>';
echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
echo '<a href="'. $tags_string .'" >-</a></div>';
if (false !== strpos($Path, $result_slug[$s])) {
echo '<style>#cat-hide-'. $s .'{display:none;}</style>';
echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>';
echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
echo '<a href="'. $tags_string .'" >-</a></div>';
}
}