$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Display a text message if the field is not found and not if found|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Display a text message if the field is not found and not if found

matteradmin7PV0评论

I am trying to display a message like "Sorry no information here" if a field is not found and if field is found, no message should appear. I am using the ACF plugin for displaying fields on the front end in a user profile.

This is my code:

<?php $user_ID = get_current_user_id(); 

            $label = 'user_' . $user_ID;
            the_field('Information', $label); ?>

If anyone has an idea, I have tried a lot of things but nothing helps. Thanks in advance. Nico

*Update: In fact, with ACF plugin for wordpress, I have created a field to display in user account in the backend of wordpress. So now I want to display this field (information) in the frontend account of the user.
If I need to put a message for my client, I put this message in the wordpress backend user account.
So in the frontend account, if I don't have put any message in this field (information), I want to display an automatic message like: "You don't have information yet"
If I put a message in the field (information) in the wordpress backend user account, I want the automatic message disappear and my message is displayed.

for now the message I put in field (information) in the backend account user is displayed correctly in the frontend user account *

I am trying to display a message like "Sorry no information here" if a field is not found and if field is found, no message should appear. I am using the ACF plugin for displaying fields on the front end in a user profile.

This is my code:

<?php $user_ID = get_current_user_id(); 

            $label = 'user_' . $user_ID;
            the_field('Information', $label); ?>

If anyone has an idea, I have tried a lot of things but nothing helps. Thanks in advance. Nico

*Update: In fact, with ACF plugin for wordpress, I have created a field to display in user account in the backend of wordpress. So now I want to display this field (information) in the frontend account of the user.
If I need to put a message for my client, I put this message in the wordpress backend user account.
So in the frontend account, if I don't have put any message in this field (information), I want to display an automatic message like: "You don't have information yet"
If I put a message in the field (information) in the wordpress backend user account, I want the automatic message disappear and my message is displayed.

for now the message I put in field (information) in the backend account user is displayed correctly in the frontend user account *

Share Improve this question edited Apr 3, 2019 at 21:49 Nicolas Logerot asked Apr 3, 2019 at 16:50 Nicolas LogerotNicolas Logerot 676 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 3

Are you just looking for a simple if then statement? Assuming that your fields are set up properly, then this code should work:

<?php 
    $user_ID = get_current_user_id(); 
    $label = 'user_' . $user_ID;

    if (get_field('Information', $label)) {
      //there is data;
    } else { 
      echo 'Sorry no information here';
    }
?>

the_field() echos the field value, while get_field() returns the field value which can be checked using if statement to display a message. Documentation

<?php 

$user_ID = get_current_user_id(); 

$label = 'user_' . $user_ID;

//the_field('Information', $label);

if (! get_field('Information', $label)) {

      echo 'Sorry no information here';

    } 
?>

I finally find the solution, thanks you Rudtek, and thank you Qaisar Feroz for all of your time and code.

So this is the working code:

<?php 
    $user_ID = get_current_user_id(); 
    $label = 'user_' . $user_ID;

    if (get_field('information', $label)) {
      //there is data;
      echo get_field('galerie', $label);
    } else { 
      echo 'Sorry no information here';
    }
?>
Post a comment

comment list (0)

  1. No comments so far