WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Felix
    Member
    Posted 1 year 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?

    http://wordpress.org/extend/plugins/custom-fields-creator/

  2. madalin.ungureanu
    Member
    Plugin Contributor

    Posted 1 year ago #

    Hi!
    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
    Member
    Posted 1 year 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

About this Topic

Tags

No tags yet.