Home Forums General Issues Problem with get_field() and passing parameters


Problem with get_field() and passing parameters

  • Hello people,

    So, I have a weird problem with get_field() function.

    Here is my problem:
    I’ve created a class with a function that will pass my parameters for checking if is some field empty or not.

    I’ve many declared variables, so I don’t want to repeat code again and again.

    For example: In file1.php I have this class:

    class wow {
        public $emptyString = '';
        public $data;
        function emptyValue($emptyString, $data) {
            $empty = empty($data) ? $emptyString : $data;
            echo $empty;
    $wow = new wow();

    And in file2.php I call the function:

    include 'file1.php';
    $header_first_icon_title = get_field ('header_first_icon_title');
    $wow->emptyValue('Field is empty', $header_first_icon_title );

    This only works when I declare $header_first_icon_title = get_field ('header_first_icon_title'); right to the $wow->emptyValue('Field is empty', $header_first_icon_title ); Literally in one line above.

    If I declare $header_first_icon_title = get_field ('header_first_icon_title'); on the top of the file, and I call $wow->emptyValue('Field is empty', $header_first_icon_title ); for example after 2, 3 houndres of html lines this will not catch the $data. It will only return "Field is empty".

    Also, for example, if I do something like this:
    $wow->emptyValue('Field is empty', get_field ('header_first_icon_title')); everything working.

    I’m not sure why this happens. I don’t get any errors. I want to declare all variables on the top, so I can call them where I need them later in the file.

    If someone can help me/explain to me why this has this behavior I would be more then thankful.

Viewing 1 post (of 1 total)

The topic ‘Problem with get_field() and passing parameters’ is closed to new replies.