brookruck Posted July 24, 2014 Share Posted July 24, 2014 I am working on a site Wordpress site where I have used a plugin to create some custom fields that appear when a user is creating a new page. The code below is a snipet from the template that calls those custom fields and places the user input into the proper sections of the page. The first line is working perfectly, the second piece of code is where my error is coming from. The code in bold is the call to the user input url. I need this to be input into the button shortcode. I am not very experienced with php, so I am hoping that I have just made a simple syntax error. Any help would be greatly appreciated! .... <p><?php echo types_render_field("copy-section");?></p> <?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . echo types_render_field("signup-link"); . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?> .... Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/ Share on other sites More sharing options...
cyberRobot Posted July 24, 2014 Share Posted July 24, 2014 There may be more issues, but the things that jump out at me are the extra "echo" and semi-colon. Try changing this: <?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . echo types_render_field("signup-link"); . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?> To this: <?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . types_render_field("signup-link") . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?> If that doesn't work and you're still getting errors, please let us know what the exact message is (or messages are). Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/#findComment-1486060 Share on other sites More sharing options...
brookruck Posted July 24, 2014 Author Share Posted July 24, 2014 Thank you, cyberRobot! At least now I am not getting a blank screen anymore. However, it still isn't inserting the user data into the href/url. There is just a '#' where it should be. Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/#findComment-1486067 Share on other sites More sharing options...
cyberRobot Posted July 24, 2014 Share Posted July 24, 2014 Sorry, I'm not very familiar with do_shortcode() or types_render_field(). Have you tried echoing the result from types_render_field() to see if it's what you expect? <?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . types_render_field("signup-link") . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); echo '<p>types_render_field() Output: ' . types_render_field("signup-link") . '</p>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/#findComment-1486074 Share on other sites More sharing options...
brookruck Posted July 25, 2014 Author Share Posted July 25, 2014 Thanks again for taking the time to reply. I tried your suggestion, and it did echo the correct data. I still wasn't able to get it to put it into the proper url field for the button shortcode though. But we ended up having to scratch that custom field and do a work around in order to complete the project on time. It does still bother me that I wasn't able to work this issue out though! Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/#findComment-1486137 Share on other sites More sharing options...
cyberRobot Posted July 25, 2014 Share Posted July 25, 2014 It does still bother me that I wasn't able to work this issue out though! If you're still interested in looking into the problem, it may help to post the code for the "button" shortcode? Quote Link to comment https://forums.phpfreaks.com/topic/290086-using-custom-fields-to-populate-an-href/#findComment-1486142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.