Home Forums General Issues Advanced Custom Fields in a Custom Text Widget Reply To: Advanced Custom Fields in a Custom Text Widget

  • We have custom fields set up this way:

    screenshot text fields

    A PHP programmer initially set up the sidebar HTML/PHP code in the template pages (home.php, page.php, etc). In there, the custom fields work, the hyperlinks are generated correctly. The custom text fills in to match the logged in user’s custom fields, creating custom links.

    I’m trying to move back to a more standard usage of the WordPress sidebar, where some widgets can be changed in the sidebar, as normal.

    For the widget where the custom text will populate, I set up a Custom Text Widget, with a plugin to allow it to accept PHP/HTML. Then, I pasted the code in. The variables aren’t processing when used in this widget. They are generated as $my_goals, rather than the value for $my_goals filling in, for example.

    This is the code in the widget:

    <ul class="menu" id="menu-my-stuff">
    <?php $my_goals =  get_field('_my_goals', 'user_'. $author_id ); $my_goals = $my_goals ? $my_goals : '#';?>
    <li class="menu-item ">
    	<?php echo "<a target=blank href=$my_goals>my Goals</a>" ?>
    <?php $my_analytics =  get_field('_my_analytics', 'user_'. $author_id ); $my_analytics = $my_analytics ? $my_analytics : '#';?>
    <li class="menu-item ">
    	<?php echo "<a target=blank href=$my_analytics>my Analytics</a>" ?>
    <li class="menu-item"><a href="" target="_blank">my Top Prospects</a></li>
    <?php $my_ad_scheduler =  get_field('_my_ad_scheduler', 'user_'. $author_id ); $my_ad_scheduler = $my_ad_scheduler ? $my_ad_scheduler : '#';?>
    <li class="menu-item ">
    	<?php echo "<a target=blank href=$my_ad_scheduler>my Ad Scheduler</a>" ?>
    <?php $my_commission_report =  get_field('_my_commission_report', 'user_'. $author_id ); $my_commission_report = $my_commission_report ? $my_commission_report : '#';?>
    <li class="menu-item ">
    	<a target=blank href="[acf field="{$my_commission_report}"]">my Commission Report </a>
    	<?php echo "<a target=blank href=$my_commission_report>my Commission Report</a>" ?>
    	<?php echo( '<a href=$my_commission_report>Click Me</a>' ); ?>
    <p><?php the_field('$my_commission_report'); ?></p>