Support » Themes and Templates » If Post Meta Equals Current Title Conditional

  • 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.

       $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="<?php echo get_post_meta($page->ID, "p30-itunes-song", true); ?>" class="blank">BUY</a></td>
            <?php if ($page->post_content) { ?>
            <tr class="gigpress-info">
            <td colspan="3"><?php echo $page->post_content ?></td>
            <?php } ?>
    <?php $i++;
       } } ?>


Viewing 3 replies - 1 through 3 (of 3 total)
  • 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()) { ?>



    Forum Moderator

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

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

    (you could also use the_title('','',false)
    setting the $display parameter to false )

    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.