-1

To show a sidebar in a Wordpress theme you do this:

<?php dynamic_sidebar( 'sidebar' ); ?>

But I am trying to insert a value from a custom field where the sidebar name is so I have this solution which does not work:

<?php $field = get_field_object('section_specific_sidebar'); ?>

<?php dynamic_sidebar( echo $field['value'] ); ?>

I've tried many things and have searched quite a bit but I'm not totally sure of the language I should be using to search. Could anyone show me what I'm missing? Adding the single quotes around the $value doesn't work either it seems.

vectyr
  • 13
  • 7

1 Answers1

0

What is the value of $value? Looking at the ACF docs you likely want to use name or key as the array key.

rich
  • 1,224
  • 1
  • 19
  • 36
  • The value would be one of several options from a select menu such as: "realestate", "community", etc. If I put $value outside of it will show up, but not when it is in the parenthesis. I think I need the single quotes but they aren't working so there must be some formatting that is off. – vectyr Feb 26 '20 at 20:38
  • I guess to clarify, I want to be able to populate what is in dynamic_sidebar() with the value from a custom field. Can't seem to figure out how to do it. – vectyr Feb 26 '20 at 23:17
  • You don't need quotes around the variable no. dynamic_sidebar requires the index, name or ID as the parameter. I would check what $field is using a print_r and look at what you are passing to dynamic_sidebar as it likely it isn't what you think it is. – rich Feb 27 '20 at 10:28
  • Unfortunately, my knowledge doesn't go deep enough to understand your instructions. Thanks for trying to help, I looked into everything you suggested but I'm on a crunch and I'm probably going to try a less elegant solution. – vectyr Feb 27 '20 at 14:42
  • If you do a print_r($field); you should see the contents of the array. You are looking for the key with the value you want (eg realestate); That would be what you use to as the dynamic_sidebar value. – rich Feb 28 '20 at 08:43
  • I'm trying really hard to understand what you are saying but I have no clue how to do a print_r($field), I know just enough about php to do very, very basic stuff. I'm just trying to figure out what goes here: Or I could be trying to solve this in the wrong way altogether. – vectyr Feb 28 '20 at 17:30
  • Okay, you should probably read up on how to use PHP to be honest, but... before you do dynamic_sidebar(), type in print_r($field); that will output the contents of the $field array. From there you will see the key=>value. Where the value is what you want. so look at the key and use that as what you pass to dynamic_sidebar. I would take a look at the PHP docs on what an array is https://www.php.net/manual/en/language.types.array.php – rich Feb 29 '20 at 18:37