Skip Navigation

[Resolved] PHP conditional statements not working after update to Toolset Types 3.4.14

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 23 replies, has 3 voices.

Last updated by LandruF8417 3 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2183839

I have had this condition working fine on the site prior to Toolset Types 3.4.14.

<?php if( get_post_meta($postid, 'wpcf-publications') ): ?>
	<h2><span>Publications</span></h2>
	<?php echo  get_post_meta($postid, 'wpcf-publications', true); ?>
<?php endif; ?>	

I recently realized that when I create new posts since updating to Types 3.4.14, the conditional statement do not working properly anymore.

I also tried:

<?php 
$publications = get_post_meta(get_the_ID(),'wpcf-publications');
//Then you run and if statement on the field like this
if (!empty($publications)){
	//do something
	echo '<h2><span>Publications</span></h2>';
	echo  get_post_meta($postid, 'wpcf-publications', true);
	}
?>

But that does not work either.

Can you help me find a solution to this issue.

Thanks

#2183857

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

What is the context? Where does this code live, in a PHP template for displaying single posts (of some type)?

Within the loop section of that template?

Where does the value of $postid come from?

What type of field is "publications"?

And the problem is that even when the post being displayed does have a value it is not being output? (And the h2 title is not being output either?)

#2183889

It's in a single post template

I have this for the $postid value:

$postid = $wp_query->post->ID;

publications is a WYSIWYG type filed

The problem is that the "publication" field does not have a value in the admin, but it is being displayed in the front end. The h2 should not display either. They should only display if the filed has a value.

#2184041

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

We need to go through the code to ensure that the correct values or the expected values are being returned.

If you were to dump the post ID onto the page, does the correct ID display? This is where we can start to debug to ensure that everything is ok.

Thanks,
Shane

#2184063
<?php echo $postid; ?>
<?php echo get_the_ID(); ?>

both returns the correct post id of "9038"

#2184157

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

Then the next step is to check if the get_post_meta is returning the correct value when passing the ID into the function as well as the field name.

Once you're able to identify where the disconnect is then it should be able to help you with resolving the issue.

Thanks,
Shane

#2184169

I entered value text "pending" in the "publication" field of the post.

I used this code to display the value:

<p><?php echo get_post_meta($postid, 'wpcf-publications', true); ?></p>
<p><?php echo get_post_meta($wp_query->post->ID, 'wpcf-publications', true); ?></p>

Results:

both lines of code displayed the text "pending"

#2184185

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

If both lines are displaying pending then your code below should still work.

<?php if( get_post_meta($postid, 'wpcf-publications') ): ?>
    <h2><span>Publications</span></h2>
    <?php echo  get_post_meta($postid, 'wpcf-publications', true); ?>
<?php endif; ?>   

Would you mind allowing me to have admin access to the site as well as a link to the page where I can see the code working ?

Thanks,
Shane

#2184189

I don't have the ability to create a temp php access. Can I use the duplicator plugin here (https://toolset.com/faq/provide-supporters-copy-site/) to send you a copy of the site so that you can check instead?

#2184191

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

Yes this will work as well. I've enabled the private fields for you to provide the copy.

#2184701

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

I have a bit of an issue with the duplicator package. It seems to not have the website files as well as the database attached to it.

The only thing that is inside the duplicator zip file is the installer.php backup file. Can you create the duplicator package again. It should be atleast 200mb for a basic wordpress install.

The current file that you uploaded is only 3.5mb

Thanks,
Shane

#2184739

Hi Shane,

The link I sent includes a separate zip file that has the webfiles. I had to do it manually because I got server errors while using duplicator. See the zip file named webfiles-backup.zip for the webfiles.

#2184743

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

I read through your comments once more and saw that you said that both lines below are returning "pending".

<p><?php echo get_post_meta($postid, 'wpcf-publications', true); ?></p>
<p><?php echo get_post_meta($wp_query->post->ID, 'wpcf-publications', true); ?></p>

Can you double check that the post with ID "9038" doesn't actually have a value assigned in the field. Secondly what kind of field is this? Is it a select field or checkbox ?

Based on what the functions are returning the field itself does have a value. Does this also hold true for other fields with Empty values ? Also is "Pending" a valid option for this field.

Thanks,
Shane

#2184783
Screen Shot 2021-10-01 at 11.40.39 AM.png
Screen Shot 2021-10-01 at 11.44.08 AM.png

Hi Shane,

When I enter the value "pending" in the field, it displays on the front end as "pending". When I delete the value from the field, It remove the text "pending" from the front end.

It is a text Multilined WYSIWYG field.

There are several fields that has this issue. See screenshts of backend and frontend.

The issue only happens when new posts are created or old posts are edited. Existing unedited post are fine, But if I edit or update an existing post, It will have the same issue im describing.

The H2 heading should not display if the fields are empty

The problem started happing after the most recent update to the plugins of Types and Views. But I don't think it's an issue with Views because I'm not using Views to display the content. I'm using the PHP code I sent you.

Hope this helps explain

#2184935

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Landru,

Thank you for the screenshots and confirming.

However i'm having some challenges restoring the backup given the way the files were provided. Are you able to create the backup using the All in One Migration plugin ?

If yes then can you create an account then create the backup using the plugin ?

Thanks,
Shane