• I made this statement to say if it has a custom field called cust_cats then to output the cust_cats field.

    elseif ( is_single() && !is_attachment() && get_post_meta($wp_query->post->ID, cust_cat, true) ) {
    	  $cat = get_post_meta($post->ID,'cust_cat',true);
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
          echo $currentBefore;
          the_title();
          echo $currentAfter;
    
        } 
    
    	elseif ( is_single() && !is_attachment() && !get_post_meta($wp_query->post->ID, cust_cat, true) ) {
          $cat = get_the_category(); $cat = $cat[0];
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
          echo $currentBefore;
          the_title();
          echo $currentAfter;
    
        }

    For some reason it doesn’t work.. Any ideas? thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • elseif ( is_single() && !is_attachment() && get_post_meta($wp_query->post->ID, cust_cat, true) ) {
    	  $cat = get_post_meta($post->ID,'cust_cat',true);

    if you compare the get_post_meta() in both lines, you will see that for some reason it is different – and the one in the if-statement does not look right;

    try:

    elseif ( is_single() && !is_attachment() && get_post_meta($post->ID, 'cust_cat', true) ) {
    	  $cat = get_post_meta($post->ID,'cust_cat',true);
    Thread Starter markey101101

    (@markey101101)

    This doesn’t work either. What it is saying is that if the custom field exists use the following and the other statment says if the custom field doesn’t exist.

    For some strange reason it just doesn’t work.

    Maybe the && get_post_meta is the wrong code to use?

    Thanks

    Thread Starter markey101101

    (@markey101101)

    I got it working Yipee!

    elseif ( is_single() && !is_attachment() && get_post_meta($post->ID, 'cust_cat', true) ) {
    	  $cat = get_post_meta($post->ID, 'cust_cat', true);
          echo $cat;
          echo $currentBefore;
          the_title();
          echo $currentAfter;
    
        } 
    
    	elseif ( is_single() && !is_attachment() && !get_post_meta($post->ID, 'cust_cat', true) ) {
          $cat = get_the_category(); $cat = $cat[0];
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
          echo $currentBefore;
          the_title();
          echo $currentAfter;
    
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Why doesn't this if statment work properly?’ is closed to new replies.