Hmm strange... when I use an URL field, it doesn't work, the link gets corrupted. But when I use a single line field with an URL in it, it does work - but then I can't validate the URL on input.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
When you use URL field you have to use extra attribute output='raw'.
For example:
<a href="[types field='woonplaats' output='raw' item='[wpv-search-term param='contact_id']'][/types]">Woonplaats</a>
Yes that works, thanks!
I know this is out of the scope of support, but I'm hoping it's a small problem for you to fix 🙂
I've added other pages to your code to get the ID parameter on those as well (see the code below), but when I click on another page, the ID parameter gets lost... please see this screen recording to see what I mean: hidden link
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_filter( 'wp_get_nav_menu_items','func_add_kapper_id_to_menu', 20, 3 );
function func_add_kapper_id_to_menu( $items, $menu, $args ) {
global $post;
if( is_admin() )
return $items;
if($post->post_type=="kapper"){
foreach( $items as $item )
{
if( 'Contact' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
if( 'Wie ben ik' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
if( 'Prijslijst' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
}
}
return $items;
}
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I've adjusted the code I've added as given under:
add_filter( 'wp_get_nav_menu_items','func_add_kapper_id_to_menu', 20, 3 );
function func_add_kapper_id_to_menu( $items, $menu, $args ) {
global $post;
if( is_admin() )
return $items;
if($post->post_type=="kapper" or ($post->ID==20 and isset($_GET['contact_id'])) ){
foreach( $items as $item )
{
if( 'Wie ben ik' == $item->title){
$post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
$item->url = $item->url.'?contact_id='.$post_id;
$items[] = $item;
}
if( 'Prijslijst' == $item->title){
$post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
$item->url = $item->url.'?contact_id='.$post_id;
$items[] = $item;
}
if( 'Contact' == $item->title){
$post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
$item->url = $item->url.'?contact_id='.$post_id;
$items[] = $item;
}
} }
return $items;
}
You need to make sure on what page/post you are and accordingly you will require to set the conditions with the above hook. I hope this helps and please kindly open a new ticket for every new question.
That absolutely helps! Thank you so much, couldn't have done this without you 🙂