I have this PHP script to fetch tags (as we use WordPress as a CMS, the tags are "categories" for our partners).... However, I'm trying to free up "tags" to be used on blog posts - but currently the code below fetches ALL tags - how can I restrict this to only tags I specify (happy to enter each Tag ID)
Here is the code:
<?php
/*
Template Name: Find A Partner Index
*/
get_header(); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
<style>
.head_padding {
display: none;
}
.partner_tabs {
padding:0;
margin:0;
list-style:none;
}
.nav-sidebar > .active,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:active,
.nav-sidebar > .active > a:visited,
.nav-sidebar > .active > a:link,
.nav-sidebar > .inactive,
.nav-sidebar > .inactive > a:hover,
.nav-sidebar > .inactive > a:active,
.nav-sidebar > .inactive > a:visited,
.nav-sidebar > .inactive > a:link,
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover {
border-left: 2px solid #f08f00;
color: #f08f00;
padding-left: 12px
}
.nav-sidebar > .inactive > a {
padding-left: 5px;
font-family: 'Open Sans', sans-serif
}
.nav-sidebar > .subinactive > a {
font-size: .9rem;
margin-left: 65px;
margin-right: 45px
}
.nav-sidebar > .subinactive > a:hover {
font-size: .9rem;
margin-left: 65px;
margin-right: 45px;
border-left: 2px solid #f08f00;
color: #f08f00;
transition: all .3s ease-in-out;
padding-left: 15px
}
.nav-sidebar > .inactive > a:hover {
border-left: 2px solid #f08f00;
color: #f08f00;
padding-left: 10px;
transition: all .3s ease-in-out;
background-color: transparent
}
.partners_menu {
border-bottom:2px solid #e4e4e4;
border-top:1px solid #fff;
}
.partner-more-icon {
display: inline-block;
width: 93px;
height: 17px;
background: url(/wp-content/themes/volo/images/volo-partner-details-button.png) no-repeat 0 0;
text-indent: -2000em;
z-index: 999;
position:relative;
}
.ui-tabs-active a .partners_menu {
border-left: 2px solid #f08f00;
color: #f08f00;
padding-left: 20px;
}
.sub_nav_background {
border: 1px solid #d4d4d4;
border-radius: 7px;
background: url(/wp-content/themes/volo/images/partner-sub-nav-lng-bg.png) repeat-x 0 0;
height:50px;
}
.sub_nav_background_shadow {
border-radius: 7px;
box-shadow: 4px 4px 6px #ebebeb;
}
.search-submit {
border: 1px solid #008C83!important;
border-radius:5px;
background-color: #02A79C!important;
color:#fff;
cursor: pointer;
display: inline-block;
}
.region-button {
border: 1px solid #008C83!important;
border-radius:5px;
background-color: #02A79C!important;
color:#fff;
cursor: pointer;
display: inline-block;
}
input[type="search"] {
-webkit-appearance: none;
background-color: rgba(255,255,255,.7);
border-top: 1px solid #e4e4e4;
border-left: 1px solid #e4e4e4;
border-right: 1px solid #f5f5f5;
border-bottom: 1px solid #f5f5f5;
font-family: Open Sans;
font-weight: normal;
color: black;
padding-left: 3px;
}
</style>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$thumb_id = get_post_thumbnail_id(get_the_ID());
if(count($alt)) echo $alt;;
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full' , true);
$thumb_url = $thumb_url_array[0]; ?>
<div class="misc_banner_con para_1" style="background-image:url(<?php echo $thumb_url; ?>)"></div>
<div class="bottom_right_corner_bar">
<div class="padbot80">
<div class="container marbot30">
<div class="row martop30">
<div class="col-md-12">
<h1 class="marbot20 font34 title green_txt">
<?php the_title(); ?>
</h1>
</div>
</div>
<div class="row">
<div class="col-md-<?php if(get_field('sidebar')) { echo '8'; } else { echo '12'; }?>">
<?php the_content(); ?>
</div>
<?php if(get_field('sidebar')) { ?>
<div class="col-md-4 lbreak padleft30 martop20 padtop30 padbot30"> <?php echo get_field('sidebar');?> </div>
<?php }?>
</div>
<?php endwhile; else : ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
<div class="row grey_bg martop20 hbreak" id="tabs">
<div class="col-sm-3 padtop30 rbreak">
<div class="pad10 red_txt font20 title">Partner type</div>
<ul class="nav-sidebar partner_tabs" style="padding-top:20px;">
<?php
$tags = get_tags('order=ASC&orderby=name');
foreach ( $tags as $tag ) {
$tag_name = $tag->slug;
echo '<li><a href="#tabs-'.$tag->slug.'">';
echo '<div class="partners_menu green_txt padleft20 padright20 padtop10 padbot10 float_left marright20" style="width:100%;">' .$tag->name. '</div>';
echo '</a></li>';
wp_reset_postdata(); }
?>
</ul>
</div>
<div class="col-sm-9 white_bg">
<div class="row padleft20 padtop5">
<div class="sub_nav_background_shadow">
<div class="sub_nav_background pad10">
<div style="padding-bottom:9px;padding-top:1px;float:left;">
<div class="search-box float">
<form role="search" method="get" class="search-form" action="<?php echo get_permalink( 6411 ); ?>">
<label>
<span class="screen-reader-text" style="font-family:Open Sans;font-weight:normal;">I want to search for:</span>
<input type="search" class="search-field" placeholder="Search our partners…" value="" name="swpquery" title="Search for:">
</label>
<input type="submit" class="search-submit" value="Search">
</form>
</div>
</div>
<div style="padding-left:40px;padding-bottom:9px;padding-top:1px;float:left;">
<div class="search-box">
<div class="dropdown">
<button class="region-button dropdown-toggle" type="button" data-toggle="dropdown">Region
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">UK</a></li>
<li><a href="#">US</a></li>
<li><a href="#">All</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row padleft10 padtop30">
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'slug',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'term_id',
'field' => 11
),
array(
'taxonomy' => 'tag',
'field' => 'term_id',
'field' => array( /* Your Tag IDs */ ),
'operator' => 'IN'
)
)
);
$post_query = new WP_Query( $args );
if ( $post_query->have_posts() ) {
while ( $post_query->have_posts() ) :
$post_query->the_post();
// Inner loop stuff code
?>
<div class="row">
<?php
while ( have_posts() ) : the_post();
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'medium', true);
$thumb_url = $thumb_url_array[0];
$post_id = get_the_ID();
?>
<div class="col-md-6 col-sm-5 col-xs-7 pad10 center"> <a href="<?php the_permalink(); ?>">
<div class="partners_container">
<div class="row" style="height:125px;">
<div class="col-md-12 col-xs-12"><div class="left"> <img src="<?php echo $thumb_url; ?>" height="100%" alt="Volo Commerce Partners - Multichannel Automated Back Office Software. eBay, Amazon, Rakuten" title="Volo Commerce Partners - Multichannel eCommerce Software. Stock & Inventory Management"/><div class="partner-more-icon"></div></div></div>
</div>
<div class="padtop10" style="text-align:left;font-weight:bold;color:#f08f00!important;"> <?php echo '<div>' . the_title() . '</div>';?> </div>
<div class="padtop10 left"> <?php echo '<div>' . the_field('partner_page_description', $post_id ) . '</div>';?> </div>
</div>
</a> </div>
<?php
endwhile;
?>
</div>
</div>
<?php
endif;
wp_reset_postdata();?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
If anyone could be so kind to tell me how I fetch ONLY certain tag ID's - that would be absolutely perfect!
Thanks muchly!
$tag->name
and then in next line you try to get tag name by$tag_name
? Also put whole code, because we don't know from where did you get$tag
variable