• Resolved rblatz

    (@rblatz)


    So I’m trying to assign and manipulate a php variable using Airpress shortcode, I’d be willing to using the manual requests as easily as the shortcodes.

    I’ve done some testing and when I assign a PHP variable with a shortcodes value like so:

    $x = array(‘[apr field=”count”]’);

    variable $x can output the correct info with echo and gettype() says that it is a string.

    If I try to do anything to $x that I can do to a manually assigned string variable it does not work the right way. When using an IF statement the $x variable does not compare properly to either the int number that is assigned or a string of the same number. RegEx does not function on it properly. Normally you can convert a number set as a string to an Integer or Float value. If I try to do that I just get a 0.

    At this point I have no idea what is going on with this variable. I’ve put several hours into it because of the mystery and I can’t figure out what’s happening.

    Any thoughts? Should I do this a different way?

Viewing 1 replies (of 1 total)
  • Plugin Author Chester McLaughlin

    (@chetmac)

    The apr shortcode must be evaluated by WordPress in order to produce anything other than the string you provide. For example: $x = "[apr field='count']"; is merely a string—nothing more, nothing less.

    However, if I do this:

    $x = do_shortcode("[apr field='count']")

    it will be actually ‘execute’ the shortcode apr with your parameters field="count".

    If you’re working in PHP directly, it’s roughly equivalent to:

    $x = $post->AirpressCollection[0]['count'];

    In reality it’s actually doing this in order to accommodate values from multiple records:

    
    $x = implode("\n", array_map(function ($record) { return $record['count']; }, $post->AirpressCollection) );
    
Viewing 1 replies (of 1 total)
  • The topic ‘Can’t manipulate php variable with Airpress values’ is closed to new replies.