Hello I was wondering if someone could help me out. I am creating a single.php page with custom meta data. I would like the custom post type associated with the single.php to display this custom meta. i would like to have an if statement so that only specific meta data will display if the custom post type is associated with a specific taxonomy.
<?php
if(taxonomy_exists('websites')){
echo ' get_post_meta($post->ID, 'Website_URL', true)';
}
else{
echo ' get_post_meta($post->ID, 'Website_URL',false)';
}
?>
but would like this to be enclosed in a ul li like:
<ul class='post_meta'>
<li><span class='post-meta'>name:</span> <?php echo get_post_meta($post->ID, 'name', true); ?></li>
<li><span class='post-meta-key'> Description:</span> <?php echo get_post_meta($post->ID, 'short', true); ?></li>
<li><span class='post-meta-key'> <?php
if(taxonomy_exists('websites')){
echo ' get_post_meta($post->ID, 'Website_URL', true)';
}
else{
echo ' get_post_meta($post->ID, 'Website_URL',false)';
}
?> </li>
</ul>
Thank you in advanced :)
Not sure if i understand you at 100%, so i'm providing 2 versions of the code - feel free to try them both.
Version 1: Checks if the post has been assigned to a term "webdesign" of the taxonomy "category":
if ( has_term('webdesign', 'category') ) {
$website = get_post_meta(get_the_ID(), 'Website_URL', 1);
echo '<li>' . $website . '</li>';
}
Version 2: Checks if the post has any terms of the taxonomy "webdesign":
$terms = wp_get_object_terms(get_the_ID(), 'webdesign');
if($terms && is_array($terms)) {
$website = get_post_meta(get_the_ID(), 'Website_URL', 1);
echo '<li>' . $website . '</li>';
}
EDIT:
Version 3: Use the following code to display the website URL if the post has been assigned to a term "webdesign" of the taxonomy "portfolios":
if ( has_term('webdesign', 'portfolios') ) {
$website = get_post_meta(get_the_ID(), 'Website_URL', 1);
if( $website ) {
echo '<li>' . $website . '</li>';
}
}