Php code as Dynamic Data

Today if we want php dynamic data we have this “Output PHP…” option:
19-05-VbdeAFLs

which is:

  1. Very limiting:
    You can’t for example set a query loop and get some data from there or so on…
    if you want something more complicated then ‘hello world’ you have to use a function
    that if isn’t avilable yet you have to write somewhere (let’s say in you functions.php file)
    and only then you can use it.
  2. Very inconvenient, because you have to write the code into one line with a view limit
    of 350px or so…

My Request is:

Have a PHP code option as dynamic data option, and when you choose it,
you will get a code window (just like in the code element):
19-05-4Qw8Ytgr

That you can write code to and will use the returned value as the data.

Just curious.

What’s wrong with having all your functions in one place like functions.php or even better WPCodeBox (where you can fine-tune them as well as organize them) and then call them with the current “echo” tag?

Maybe it would be easier to understand if you could name one or two precise examples of results you’re trying to achieve?

2 Likes

It’s not wrong. if you like it go a head :slight_smile:

But if you like me. and you use a page builder because your looking for some faster workflow. then When for example, i need something like ACF custom field of the current post author user (which isn’t available as dynamic data), or if you want to have some conditions on content (without having to add two seperate elements and conditions for each one of them to show and hide on, and have to handle them both and see duplicated elements on the screen preview) and just want to have a simple if (get_field(x) > 0 echo y, else echo z… and so on), it’s much easier to just type it on the place, then to:

  1. click on icon to go to wordpress admin
  2. click on “wp code box” menu.
  3. add new snippet of code and wrap with function choose_name_for_that_function(){}.
  4. save it. activate it.
  5. go back to page builder tab and refresh it.
  6. choose “php function” in the dynamic data.
  7. add: choose_name_for_that_function() after the {echo:…

Also you are limited to the things you can pass as variables to that function in this {echo:} option.

2 Likes

I like the idea. I also want the same for div blocks . Custom php Query Loop

1 Like

Example. We have an array as a result of executing php code.

$array = [][
0 => “bar”,
‘two’ => “foo”,
];

In the dynamic data field, we write: phploop:0 (or phploop:two)

if it is a simple array, then you can output just a value, i.e. without specifying a key. write phploop:value

This way we will be able to create our own structures, such as tables or any other lists without using filter programming.

1 Like

Thank you for the examples, now I get your perspective. Hope this gets implemented :slight_smile: