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:
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>" ?>
</li>
<?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>
<li class="menu-item"><a href="http://wiki.wikigood.com/sugar" 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>" ?>
</li>
<?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>' ); ?>
</li>
</ul>
<p><?php the_field('$my_commission_report'); ?></p>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.