Custom Fields Creator
Conditional statement with array value always false (3 posts)

  1. Felix
    Posted 3 years ago #

    Hey, I'm trying to get a conditional statement with

    <?php $info= get_post_meta($post->ID, 'info'); if ( isset($info['test']) ) { ?>

    but its always a false. Any ideas?


  2. madalin.ungureanu
    Plugin Contributor

    Posted 3 years ago #

    CFC always stores it's data as serialized array( array ) even if you only have one entry or you set up a single entry meta box, so it should be if( <?php $info= get_post_meta($post->ID, 'info', true); if ( isset($info[0]['test']) ) { ?>

  3. Felix
    Posted 3 years ago #

    Thanks for your reply. Sadly, that method will always return a true (might be the php version and isset problem with multidimensional arrays?)

    Anyway, this will do the trick even though it's not pretty:

    <?php $info = get_post_meta($post->ID, 'info', true);  foreach($info as $info) { 
     if ($info['test']) { echo 'true'; } else { echo 'false'; }
      }  ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Fields Creator
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.