Support Forum
Hi Anh,
How can I pass a custom field value into a url as query string? I'm using gravity forms and I have a url field type so that I can add in my booking url. I'd like to attach some values like for example: https://demo.com/?your_parameter=[rwmb_meta id="tour_date"][rwmb_meta id="tour_name"]
So that when the user clicks the book now button and they are taken to the gravity form - it will dynamically populate that info into a field.
How can this be done? Thanks in advance!
Hi Brian,
If you are using the shortcode outside the loop (or the post), you should add the second attribute object_id
then the shortcode should be
[rwmb_meta id="field_id" object_id="post_id"]
you can find the post ID in the URL when editing the post
For further information, please follow our documentation
https://docs.metabox.io/shortcode/
Hi Long,
I'm not sure I explained it correctly. So I provided a screenshot: https://share.getcloudapp.com/DOu8ODZD
I made a custom post type of "trips" and have a handful of custom fields on the edit page like in above screenshot. What I would like to do is get to two custom field values and use them in my reservation url field as seen in screenshot. So that on the front end of the site when a user clicks the button - the url will have those two values added to the end as a query string so that it will dynamically populate a Gravity Form "field" when they get directed to that page from link.
Let me know - Thanks!
Hi Long,
I reached out to Gravity Forms. They said to ask you all if it's possible to parse the shortcodes that I'm using above in the url field? Because you need them to parsed before passing them to Gravity Forms.
Is that more clear? How would I be able to parse those shortcode values so that I can use them in my reservation url custom field?
Thanks in advance!
Hi Brian,
Parsing a shortcode in the URL is very complicated. It's very easy if you modify your code like this
<a href="https://demo.com/?your_parameter=<?php echo do_shortcode('[rwmb_meta id="tour_date"]') . do_shortcode('[rwmb_meta id="tour_name"]') ?>">Button</a>
This piece of code will help you to parse the shortcode in the URL when clicking to the button, but only one shortcode will be parsed.
https://demo.com/?your_parameter=[rwmb_meta id="tour_date"]
You can use Code Snippet to run the code and you need to find the class of the button to put on the code.
Hi Long,
Wow you're right parsing in url does look super complex.
I'll just add it into template output as you suggested in first option. One question though. I created a radio option field before the two book now url fields. So that the user could select an internal link vs external link. I set up the conditional logic in metabox and everything is working. I then added two book now buttons in output (one for external and one for internal) each with own css class.
I thought I'd be able to hide of the the booking buttons based on the radio fields value on the front-end of website. I followed your documentation and created new filter:
// Conditionally Hide Internal Reservation Button
add_filter( 'rwmb_outside_conditions', function( $conditions ) {
$conditions['.onsite-booking-url'] = array(
'hidden' => ['tour_reservation_link_option', '=', 'external'],
);
return $conditions;
} );
But this did not work. Both buttons display on front end of site. Am I missing something?
Thanks in advance!
Hi Brian,
The extension MB Conditional Logic helps you to show/hide the field or other HTML elements on the backend. This guide maybe help you to create a conditional logic when showing the elements on the frontend.
Or simply you can use a piece of Javascript code to show/hide the button. Here is an example HTML code to show the radio
<input type="radio" id="internal" name="check" value="internal" checked>
<label for="internal">internal</label><br>
<input type="radio" id="external" name="check" value="external">
<label for="external">external</label><br>
and you can use this code with Code Snippets plugin to do this trick
add_action( 'wp_footer', function() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("input[name='check']"). click(function(){
var radioValue = $("input[name='check']:checked").val();
if(radioValue == 'internal'){
$('.wp-block-button').show();
} else {
$('.wp-block-button').hide();
}
});
});
</script>
<?php
} );
a short screen record for this action https://cl.ly/2263ff2a45dc
Hi Long,
Thanks for the detailed reply and providing the js show/hide option. I didn't realize that what I was originally trying to do based on your docs was only for the backend field display. Makes sense now.
I'm all good - thanks again!