treehouse : what would you like to learn today?
Web Design Web Development iOS Development

PHP Inside tags?

  • Hi!

    I'm using PHP custom fields and I need to populate them inside a Javascript tag, but the custom fields are not showing up. They show up fine if they're not in being called in the Javascript tag.

    Does anybody have any tips on how to get around this?

  • Please give us a link to the page or make a pen. We don't know what's the problem until we see the code.

    This may sound stupid, but have you checked to make sure that your file extensions are .php and not .html?

  • Hi cizmic,

    Sure. I hope it helps: http://codepen.io/anon/pen/IACvD

    If you look around at line 4, the PHP code starts to come in. In Firebug, I look at that line and nothing outputs, it's blank.

    No, your last statement is not stupid at all! Yes, my site is in PHP, well actually in Wordpress.

  • ....and you verified all dependencies were connected, you are calling the your initialization in the 'onload' of the body? In fact, did you set up an initialization function? if not that would explain the problem, because after all the javascript has to have a way to hook into the dom...

  • Before all your JavaScript and such could you please let us know what happens when you run the below code as I feel like an empty value is been returned to $rows

      $rows = get_field('center_latitude_and_longitude');
      echo '<pre>';
      print_r($rows);
      echo '</pre>';
    
  • @kgscott284 - Well, it works fine without the PHP in there. So that's good right? I'm just trying to make all these variables easily editable by the clients.

  • @SgtLegend - I did that and it returned nothing which really helped in figuring out the problem!

    I wound up taking that same code and putting at the top of the page (before all the WP queries) and it worked so I realized it was a query problem. I wound up adding wp_reset_query(); and voila! Thank you!