Support Forum
Hi,
I am a user of Oxygen Pagebuilder, where I can add dynamic content (e.g. PHP-functions).
In addition, I am using "MB Custom Table" where a "Custom Posttype" is stored.
Now I am using the function acf_value($mb_field) to output the content in a text element (functions are stored in a Code Block/ PHP). This works as intended.
<?php
function acf_value($mb_field) {
echo rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => $wp_square] );
}
function acf_picture($mb_field) {
$output_array = rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => $wp_square] );
echo rwmb_meta( $output_array, array( 'size' => 'thumbnail' ) );
}
?>
Now I am trying the same with an image element (using a "single image", I see the single-ID of the image stored in the relevant DB-field- so "custom table" is working).
I need to get the image URL based on a PHP function.
This is done by using the dynamic data: [oxygen data='phpfunction' function='acf_picture' arguments='sq_single_image_field'] which calls the function in the code block.
But my trial with acf_picture($mb_field) is not successfull.
What I am doing wrong? How to get the (https-) URL of a single image (with the original size)?
BTW: Is there a compatibility check done with Oxygen Pagebuilder - you have addons on different other page builders....?
BTW: How long "custom table" content will be cached? How to manipulate those time?
Please extend the documentation, thanks 😉
Hi,
Use the helper function rwmb_meta() to get the field single_image
value returns an array of image information.
So you just need to echo the array key full_url to show the image URL.
function acf_picture($mb_field) {
$output_array = rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => $wp_square] );
echo $output_array['full_url'];
}
Regarding the cache, the extension MB Custom Table supports caching the query. That means, if you call the helper function several times for the same $post_id, it will only query once with the default expiration time (0 seconds). See more in this documentation https://developer.wordpress.org/reference/functions/wp_cache_set/.
OK, Thanks for your answer - maybe a mistake from my side 😉
But as far as I remember, I used an example from your webpage.
Regarding caching: if it's more or less zero (standard = 0), so it's technically caching but in reality not - so no issue... I thought it will last some minutes or hours...
Hi,
I have a big issue!
I am using Oxygen Pagebuilder.
I was using the mentioned function above and tried to get a picture rendered (using a picture block - using dynamic data).
As this support forum does not support pictures it's not possible to simply show you screenshots!
But I get an error thrown while doing so!!!
Therefore I tried (a simple way) to add a PHP block with:
<?php
acf_picture('sq_single_image_field');
?>
And it throws the following error at the backend:
Warning: Illegal string offset 'full-url' in /var/..../wp-content/...(446): eval()'d code on line xxx
Trying to enclose it with double quotes, did not solve the issue: acf_picture("sq_single_image_field");
What is the way to avoid this error message as it will break the correct rund of the build process?
Please can you advise how to avoid this error?
Hi,
The array key of image information is full_url
(underscore), not full-url
(hyphen). Can you please check it?
Hi,
OK, would be great - if this would be only the hyphen 😉
I changed the server setup to Caddy server and need to set up a new WP, so I will let you know tomorrow.
Thanks.
Hi Jens,
I've received your staging site information via Freshdesk, there are too many issues in your case to not display the field value with the Oxygen Builder while it should be.
$post_id
means the code will take the current post ID. The Page does not have the custom field => the helper function cannot get the field value.function acf_picture($mb_field) {
$output_array = rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => $wp_square] );
echo $output_array['full_url'];
return;
}
Oxygen does not know what the variable $wp_square
is when you pass only the field id to the function <?php acf_picture('sq_image_standard'); ?>
The snippet should be (fixed table name):
function acf_picture($mb_field) {
$output_array = rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => 'wp_square_content'] );
echo $output_array['full_url'];
return;
}
Or dynamic table name:
function acf_picture($mb_field, $wp_square) {
$output_array = rwmb_meta($mb_field, ['storage_type' => 'custom_table', 'table' => $wp_square] );
echo $output_array['full_url'];
return;
}
then pass the argument when calling the function <?php acf_picture('sq_image_standard', 'wp_square_content'); ?>
I've removed the setting custom table in the builder to save the field value in the default table of WordPress then the code works as well. You can check the page https://staging.wiconsult.eu/index.php/t02_single-image_php-block/.
Remember the note when creating the custom table https://docs.metabox.io/extensions/mb-custom-table/#notes.
Thanks for your detailed answer.
But still I believe there is a misunderstanding in the concept behind and some questions.
So first of all let me short explain:
I have a single table created – as you already know, without any content stored.
As you can see on the second image below: I created the content type “Square”, so a WordPress user can create or change the content.
The next images give you an idea: I am using a Repeater on each web page to show the content of those “Squares” (a single DB row each).
Only a filter is set in the repeater-query to get only the relevant content. More or less the whole page is created by this custom fields content.
The content itself will be shown by clicking on a Square – no additional page will be opened for details (so there is not a special page (with page ID).
The content is not page related; it’s like a car overview of a car-dealer (but without the need to have a single page for each of the cars).
Question/Topic 1:
Therefore I assume using a content type “Page” does not achieve the goal…
In addition, by switching to “Page” a user cannot create or change the content using WordPress if you now click on “Squares” and open e.g. “Test2” no fields of the DB are shown anymore because you changed now to “Page”.
This was the reason I chose not post type = ”page”.
I followed the guide “Using existing tables”.
Question/Topic 2:
Regarding fixed table name: Of course you are correct. Not sure, most likely the Oxygen Support changed it by trying to help. Or maybe I made a mistake…
I am using a fixed table name (no dynamic ones).
Question/Topic 3:
Regarding the function.php There is no theme used by Oxygen page builder – so you will not find it in the mentioned php-file.
But using the plugin “Snippets” is working, otherwise it would have not been possible for me to extract the content from the custom table.
So it is possible to call the metabox helper functions as well as my own ones.
Question/Topic 3:
Regarding picture shown (this was the main question):
If you click in the structure pane on the image (within the repeater) you can see that I am using the function.
By clicking on data-button you can use the php function.
But still I cannot see the picture rendered on the frontend (or on the backend) – so still there is no success currently ;-(
Thanks for your feedback
Hi,
See my screenshots:
- Snippet: https://share.getcloudapp.com/9Zu0P0Qy
- Square Test2 post ID: https://share.getcloudapp.com/P8umgmgw
- Oxygen repeater and image: https://share.getcloudapp.com/P8umgm6K
For more information, please follow this documentation https://docs.metabox.io/rwmb-meta/#arguments.
Hi Long,
many thanks (!), now I was able to successfully looping through the custom posts.
I extended the function with the WP-core $get_the_ID, so it's not static / hard-coded.
Sometimes it's not easy to get all information out of the documentation; I have read intensively but was not able to get the solution.