I am calling a bunch of posts under a certain post type in WordPress which works but I am trying to add a conditional that will check first if those post’s custom meta field (labeled “disc”) is equal to the current post’s title.
Here is what I have but this conditional does not seem to work:
<?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); ?>">BUY</a></td>
</tr>
<tr class="gigpress-info">
<td colspan="3"><?php echo $page->post_content ?></td>
</tr>
</tbody>
<?php $i++;
} } ?>
When I simply echo “get_post_meta($page->ID, “p30-disc”, true)” or “the_title()” it spits out their proper values, which are equal, so obviously something is just wrong with that conditional.
Thanks,
Wade
Turned out there is a function called get_the_title() that is used for this sort of thing. Worked perfectly.
It looks like you’re “quoting” the title function – essentially, turning it into a string, when you should just be calling it.
that should work?
You can use
get_the_title()
function to route your pages or display specific content.note this is case sensitive so if your page title is all lower case then your string should be to.