I just need to use the "wpv conditional" to check if data exists in the database for a particular custom field. If there is NO data, I would like to do something. For example, I have a custom field called "post-title-verified." I want to check for the current user and if the user left any data in "post-title-verified." So far, the following does not work I assume because I need to also limit the condition to the current user:
Please test this shortcode alone first to confirm it is displaying the user field value from the user that you need. Once this is confirmed, you can use it in the conditional shortcode like this:
[wpv-conditional if="( '[types usermeta='post-title-verified' current_user='true'][/types]' eq '' )"]
// value is empty
[/wpv-conditional]
[wpv-conditional if="( '[types usermeta='post-title-verified' current_user='true'][/types]' ne '' )"]
// value is not empty
[/wpv-conditional]
I hope this helps and please let me know how it goes.
I applied your solution that applies a shortcode that should ALWAYS get the current user. However, it does not work. Please review my video and comment:
From the video, it is now clear that the "post-title-verified" field is a post custom field which is saved with each of your "Religious Order Applications" custom post type.
For this reason, the value from it won't be available on "My Account" page directly, which I'll assume is a regular page.
Is there any special reason, you're not storing "post-title-verified" value as a user field? If you could share more details about your required workflow, I'll be in a better position to guide you accordingly.
It would also help if you could share the temporary admin login details so that I can look in the admin area to see how custom post type and fields are configured.
Your next reply will be private, which means only you and our support team will have access to it.
Important note: Please make a complete backup copy of your website, before sharing the access details.
Based on what you've shared, my understanding is that you need to hide the "Create Religious Order Form (Admin start here for client setup.)" link from "My Account" page, from a user who has once submitted that form ( "Create content - Religious Order Applications" ).
If this is correct, the most efficient way to achieve this would be to register a new single line user custom field (e.g. "Has Submitted ROA Form"), like you've registered a "Mobile Phone" field.
add_action('cred_save_data', 'check_submission_roa_form',10,2);
function check_submission_roa_form($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==6683)
{
//get the current user's ID
$user_id = get_current_user_id();
$key = 'wpcf-user-field';
$value = 'yes';
// update field value with yes
update_user_meta($user_id, $key, $value);
}
}
Note: Please replace "user-field-slug" with the actual slug of your newly created user field.
I went ahead and set up the code the way you instructed. update_user_meta does not seem to be doing anything.
Also, you haven't explained how I can build my conditional from the new User field that will now hold the "yes" value.
1) Can you please log in and check for any issues with the logic. I'm assuming wp_usermeta table holds the new value. But, I'm not seeing it updated. I have some snapshots for you to look at.
2) Can you also explain how I can build a conditional to test my new User field that will hold the "yes" value.
Thank you for waiting and sorry I couldn't follow up on this sooner.
During testing, I noticed that the custom code is working as expected.
In the new user field's settings, you have set the default value to "No", which is fine.
( screenshot 1: hidden link & screenshot 2: hidden link )
In the custom code, you've set the new automatically updated value to "no", though it would make more sense to change it to "Yes".
( screenshot: hidden link )
When I submitted the form "Religious Order Application" ( at hidden link ), the value of my logged-in user's field changed from "No" to "no", confirming that the code is actually working.
( screenshot: hidden link )
Once you've updated the value "no" to "Yes" in the custom code, you'll be able to use this field in conditions like suggested in my first message:
(I've tested and confirmed that this is working too)
[wpv-conditional if="( '[types usermeta='submitted-religious-order-application-form' current_user='true'][/types]' eq 'Yes' )"]
// Form is submitted
[/wpv-conditional]
[wpv-conditional if="( '[types usermeta='submitted-religious-order-application-form' current_user='true'][/types]' ne 'Yes' )"]
// Form is not submitted
[/wpv-conditional]