• Hi,

    I am trying to write a conditional to only show results if their certain “disc” post meta value is equal to the current post or page’s title.

    Here is my loop with the conditional I have going, which is currently just spitting out the post title for each result in the loop.

    <?php
       $pages = get_posts('numberposts=9999&post_type=song&post_status=publish&order=ASC&orderby=date');
    
       $i = 1;
       foreach( $pages as $page ) {
           $content = $page->post_title;
           if( empty($content) ) continue;
    
           $content = apply_filters('the_content', $content); ?>
    
    	   <?php if(get_post_meta($page->ID, "p30-disc", true)==the_title()) { ?>
    
    	   <tbody class="vevent">
    
    	   <?php if ($i%2===0) { ?><tr class="gigpress-row gigpress-alt">
    
           <?php } else { ?><tr class="gigpress-row"><?php } ?>
    
           <td><?php echo $page->post_title ?></td>
    		<td><?php echo get_post_meta($page->ID, "p30-length", true); ?></td>
    		<td><a href="http://itunes.com/<?php echo get_post_meta($page->ID, "p30-itunes-song", true); ?>" class="blank">BUY</a></td>
    
    		</tr>
    
            <?php if ($page->post_content) { ?>
    
            <tr class="gigpress-info">
    
            <td colspan="3"><?php echo $page->post_content ?></td>
    
            </tr>
    
            <?php } ?>
    
            </tbody>	
    
    <?php $i++;
    
       } } ?>

    Thanks,
    Wade

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wadeouellet

    (@wadeouellet)

    I realized I should rephrase the question a little better and it’s past my edit time limit so basically:

    I need a conditional that says “if” a custom field/input value is equal to the current post/page title, then do something.

    Here is what I have, but it just displays the current page title as if I was just echoing it:

    <?php if(get_post_meta($page->ID, "p30-disc", true)==the_title()) { ?>

    as you are comparing strings, you would use get_the_title() :

    <?php if(get_post_meta($page->ID, "p30-disc", true)==get_the_title()) { ?>

    http://codex.wordpress.org/Template_Tags/get_the_title

    (you could also use the_title('','',false)
    setting the $display parameter to false
    http://codex.wordpress.org/Template_Tags/the_title )

    Thread Starter wadeouellet

    (@wadeouellet)

    Thanks a ton! It worked perfectly.
    I didn’t know about that function, should come in handy.

    Thanks again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If Post Meta Equals Current Title Conditional’ is closed to new replies.