Hi All,
I have a blog which I have developed for a client which is near completion, except for one more issue.
Basically, we have created additional options within the Posts > Categories so that the user can add a Twitter, Facebook & Youtube URL. All of that has been created.
However, when I try and pull the information onto the front end of the category pages, it displays the URL's but of a different category. Some it works for fine, but I would say half just doesn't display the correct ones.
It looks like if a post within that category has also been assigned another category it uses that category's information instead.
Any ideas how I can get around this issue? The code I have so far is below (Please note, the information I am calling is within a tooltip):
[code]
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<?php
$category = get_category( get_query_var( 'cat' ) );
$terms = get_the_terms( $category->cat_ID , 'category' );
if($terms) {
foreach( $terms as $term ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<script type="text/javascript">
jQuery(function() {
jQuery('.follow_us ul li a.twitter').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_twitter1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter1']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter2']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter3']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter4']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter5']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.facebook').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_facebook1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook1']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook2']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook3']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook4']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook5']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.youtube').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_youtube1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube1']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube2']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube3']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube4']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube5']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.rss').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_rss'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_rss']; ?>" class="twitter_handle"><?php echo $term_meta['category_rss']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.twitter').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.facebook').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.youtube').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.rss').powerTip({
placement: 's',
mouseOnToPopup: true
});
});
</script>
<?php } } ?>
[/code]
Any help would be massively appreciated.
Arnav Joy answers:
try this
[code]
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<?php
$category = get_category( get_query_var( 'cat' ) );
$t_id = $category;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<script type="text/javascript">
jQuery(function() {
jQuery('.follow_us ul li a.twitter').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_twitter1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter1']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter2']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter3']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter4']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_twitter5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_twitter5']; ?>" class="twitter_handle"><?php echo $term_meta['category_twitter5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.facebook').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_facebook1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook1']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook2']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook3']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook4']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_facebook5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_facebook5']; ?>" class="twitter_handle"><?php echo $term_meta['category_facebook5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.youtube').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_youtube1'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube1']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube1']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube2'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube2']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube2']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube3'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube3']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube3']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube4'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube4']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube4']; ?></a></p><?php } ?>',
'<?php if ( $term_meta['category_youtube5'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_youtube5']; ?>" class="twitter_handle"><?php echo $term_meta['category_youtube5']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.rss').data('powertipjq', jQuery([
'<?php if ( $term_meta['category_rss'] == '' ) { } else { ?><p><a href="<?php echo $term_meta['category_rss']; ?>" class="twitter_handle"><?php echo $term_meta['category_rss']; ?></a></p><?php } ?>'
].join('\n')));
jQuery('.follow_us ul li a.twitter').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.facebook').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.youtube').powerTip({
placement: 's',
mouseOnToPopup: true
});
jQuery('.follow_us ul li a.rss').powerTip({
placement: 's',
mouseOnToPopup: true
});
});
</script>
[/code]
craigfarrall comments:
Hi,
Thanks for your help.
That unfortunately pulled up an error, by not displaying anything below.
Any other ideas?
Navjot Singh answers:
get_the_terms() accepts Post ID and not category ID.
Try changing this
$terms = get_the_terms( $category->cat_ID , 'category' );
to
$terms = get_the_terms( $post->ID , 'category' );
craigfarrall comments:
Hi,
I have changed that code, but it still doesn't display the correct information.
Any other ideas?
craigfarrall comments:
Does anybody have any other ideas? really struggling here.
Hariprasad Vijayan answers:
Hi,
How many category you are selecting while adding a post? If you are selecting multiple category for a post, remove multiple selection and check. Let me know it is working?
craigfarrall comments:
Yes, more than one category has been added to certain posts, so I think that is where I am struggling.
Any ideas?
Hariprasad Vijayan comments:
Avoid multiple selection. Hope it will work.
craigfarrall comments:
It is quite hard to avoid multiple selection, as that is what it's main purpose is.
Anybody else have any ideas on this? I really need to find a resolve for it.
Thanks.