I am trying to: understand why sudently (this behaviour is new, it happened a few days ago with no intervention in any way) the fields are not rendering as it should in the frontend.
I visited this URL: hidden link
I expected to see: a formated list (see picture)
Instead, I got: continuos plain text (see picture)
The template part code which renders the list is this:
<?php echo "<b>Datas de início:</b><br />" ?>
<?php
$child_posts = types_child_posts("evento");
foreach ($child_posts as $post) {
echo types_render_field("local", array('raw' => 'false')) . ": ";
$date = types_render_field( "data", array('style' => 'text', 'format' => 'U'));
if ( !empty( $date ) && ($date > time()) ){
echo types_render_field("data", array('style' => 'text', 'format' => 'd M'));
}
else {
echo "a definir";
}
echo " <span class='estado'>" . types_render_field("estado", array('raw' => 'false')) . "</span><br />";
}
?>
<?php wp_reset_query() ?>
"evento" is a cpt related to “curso?? cpt using Types. The code was working fine and, as a matter of fact, it was suggested in an earlier support thread some months ago.
I can't figure out what is the problem and why it only manifests when a user isn't logged in.
I need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.
I can't log using these credentials. Could you check it out?
Please retry. There was probably a typo in the password.
If you need FTP access, empower.pt for the server is enough.
Thanks.
The code below worked fine:
$date = types_render_field( "date", array('style' => 'text', 'format' => 'U'));·
if ( !empty( $date ) && ($date > time()) ){
Maybe in this "date" all dates are lower than time(), please check this.
You can use the code below to chck the value in the field, and compare to time():
echo '<pre>', types_render_field( "date", array('style' => 'text', 'format' => 'U')), ' - ', time(),'</pre>;
Please let me know if you are satisfied with my answer and if I can help you with any other related question.
I believe you didn't understand the problem, maybe I wasn't clear enough.
The code was working fine until a few days ago. And it still is when you're logged in.
But, please, load the cpt page when your logged-out: hidden link to compare with the logged-in rendering.
See the screenshots attached to this ticket? The problem is the way WordPress is rendering the fields.
Thanks.
Please try this:
1) deactivate other plugins and switch to wordpress default theme, and test again
2) if the problem still exists, please try enable wordpress debug mode, and post the debug logs here.
https://toolset.com/documentation/user-guides/debugging-types-and-views/
PHP Debugging
In case you think that Types or Views are doing something wrong (what we call a bug), you should enable PHP error logging. Again, edit your wp-config.php file and add the following:
ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
This will produce a file called ‘error_log.txt’ in your WordPress root directory. Make sure that the web server can create and write this file. If it cannot, use an FTP program to create the file and make it writable to Apache (normally, user www-data).
Thank you for your reply.
It's not easy to debug these issue switching themes, since these piece of code is a template part of the actual theme. I'll have to create a specific page template within a default theme's child to debug this.
My first objective was to understand why this only happens with this piece of code and when the user isn't logged in. Do you have any other record of something like this happening?
The only reason I can figure for this odd behavior is the code being influenced by the admin bar loading. But why now? This is working for so many months, didn't change a thing (plugin, theme, updates…). Could it be a server issue, like a PHP configuration or something?
The only code not working is this on line 15:
echo " <span class='estado'>" . types_render_field("estado", array('raw' => 'false')) . "</span><br />";
Got it to work! (Though I still don't understand why it wasn't working…)
See line 1 and 15?
<?php echo "<b>Datas de início:</b><br />" ?>
<?php
$child_posts = types_child_posts("evento");
foreach ($child_posts as $post) {
echo types_render_field("local", array('raw' => 'false')) . ": ";
$date = types_render_field( "data", array('style' => 'text', 'format' => 'U'));
if ( !empty( $date ) && ($date > time()) ){
echo types_render_field("data", array('style' => 'text', 'format' => 'd M'));
}
else {
echo "a definir";
}
echo " <span class='estado'>" . types_render_field("estado", array('raw' => 'false')) . "</span><br />";
}
?>
<?php wp_reset_query() ?>
For whatever reason, for the regular (non logged-in) user, the <br /> tag is not working. I had to change it to <br> tag.
<?php echo "<b>Datas de início:</b><br>" ?>
<?php
$child_posts = types_child_posts("evento");
foreach ($child_posts as $post) {
echo types_render_field("local", array('raw' => 'false')) . ": ";
$date = types_render_field( "data", array('style' => 'text', 'format' => 'U'));
if ( !empty( $date ) && ($date > time()) ){
echo types_render_field("data", array('style' => 'text', 'format' => 'd M'));
}
else {
echo "a definir";
}
echo " <span class='estado'>" . types_render_field("estado", array('raw' => 'false')) . "</span><br>";
}
?>
<?php wp_reset_query() ?>
I bet it's a PHP config issue, but why does it only happens with non-logged-in users?
I can not find the problem in the codes you mentioned above, if you need more assistance please duplicate same problem in a test site and fill below with login details and ftp access, I need a live website to debug this problem, thanks
I tested the URL in your test site:
hidden link
it is 404 error, please point out the problem page URL and where I can edit your PHP codes. thanks
I'm so sorry. I truncated the URL with the production site's.
The right one should be:
hidden link
Thanks.
I can see the problem in your website, but I can not duplicate same problem in my localhost, as I suggest above :
Please try deactivate other plugins and switch to wordpress default theme, and test again
And if it is your theme problem, I suggest you try contact your theme author, or post a downloadable URL for the theme/plugins needed, I need debug in my localhost.