Support » Plugins » Hacks » how link multiple custom taxonomy posts to specified page

  • 
    <?php
    $myquery['tax_query'] = array(
    'relation' => 'OR',
    array(
    'taxonomy' => 'brands',
    'terms' => array('ALL'),
    'field' => 'slug',
    ),
    array(
    'taxonomy' => 'media',
    'terms' => array('news', 'events'),
    'field' => 'slug',
    ),
    );
    query_posts($myquery);
    ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="so-post-hom">
    <h2 class="post-title"><?php the_title();?></h2>
    <div class="post-bar">
    ">Go!
    <?php endwhile; else: ?>
    <?php endif; ?>
    
    

    This may code,
    here taxonomy = brands and media taxonomy
    9 sub categories under “ALL” terms (in brands taxonomy) like Aspire , Gipsom , Lorah, etc
    i don’t want to go the brands post to single page ,but each pages have to go different specified pages.
    media is same as single page.
    So how can i set permalink ?

    -Thank you-

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator bcworkz

    (@bcworkz)

    I am not sure I understand what you want, this is my best guess. This will put a permalink to the post’s single page only if the post is assigned to taxonomy ‘media’:
    <?php if(0<count(wp_get_post_terms( $post->ID, 'media'))) echo '<a href="'.the_permalink().'">Full Post</a>'; ?>

    This will put a link to a specific page if the post is assigned the term ‘aspire’ in the taxonomy ‘brands’:

    <?php
    $flag=false;
    $terms=wp_get_post_terms( $post->ID, 'brands');
    foreach($terms as $term) {
       if('aspire'==$term->name) $flag=true;
    }
    if($flag) echo '<a href="http://example.com/brand/aspire/">Aspire</a>'; ?>

    These must be inside the “loop”. All untested but illustrates the general concept. I hope you are able to adjust the code to meet you actual needs.

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi bcworkz

    Can you please rewrite the code full ?

    -Thankyou-

    Moderator bcworkz

    (@bcworkz)

    Sorry, no. I’m not that sure I know what you want. Place the code provided anywhere in the “loop” below the line beginning <?php if ( have_posts() ) : while ( have_posts() ) and above the line <?php endwhile; else: ?>

    See if that’s anything close to what you wanted. You can move it around in the loop, above of below the title, above or below Go!, etc. If my code’s output is not what you wanted, you can try to explain how it is wrong and what you want to be different.

    I cannot get to a computer consistently, so any response from me may be delayed, sorry I cannot be more responsive.

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi bcworkz, it’s working perfectly, Thank you so much. expecting your future support.

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi bcworkz

    In this code how can i add one more terms [like brands , media]

    
    <?php
    $flag=false;
    $terms=wp_get_post_terms( $post->ID, 'brands');
    foreach($terms as $term) {
    if('Chac’late'==$term->name) $flag=true;
    
    

    -Thankyou-

    Moderator bcworkz

    (@bcworkz)

    I still am not sure I understand, but I seem to be guessing well 🙂

    This time, I do not know if you really want to check for other terms in ‘brands’ or terms in other taxonomies.

    I think you mean terms in other taxonomies. If it’s just one other taxonomy, you could just get the terms and run a fornext loop for each taxonomy in sequence. This would get too redundant if more taxonomies are added. A better way is to nest the loops, then you can add more taxonomies and terms in the future quite easily.

    $flag=false;
    $taxonomies = array('brands','media');
    $show_link = array('Chac’late','video');//list any terms in any taxonomy for which to show link
    foreach($taxonomies as $taxonomy) {
       $terms = wp_get_post_terms( $post->ID, $taxonomy );
       foreach($terms as $term) {
          if( in_array( $term->name, $show_link )) $flag=true;
       }
    }

    I’m currently unable to test this to ensure it works properly. I hope it works for you. It’s you lucky day, I’ve just been able to get computer access after some time and I saw you post. I will again be subject to intermittent access, but I will check back when I can to see how you’re doing.

    Thread Starter Shihab Malayil

    (@shihabmalayil)

    Hi bcworkz, Thank you for supporting me.
    terms under media not getting links.

    the code

    
    <?php
    $myquery['tax_query'] = array(
    'relation' => 'OR',
    array('taxonomy' => 'brands',
    'terms' => array('ALL'),
    'field' => 'slug',
    ),
    
    array(
    'taxonomy' => 'media',
    'terms' => array('news', 'events'),
    'field' => 'slug',
    ),
    );
    query_posts($myquery);
    ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="so-post-hom">
    <h2 class="post-title-home"><?php the_title();?></h2>
    														<h3 class="post-desc">
    <?php echo esc_html( get_post_meta( get_the_ID(), 'designers', true ) ); ?>
    </h3>
    <div class="post-bar">
    <?php
    
    $flag=false;
    $taxonomies = array('brands','media');
    $show_link = array
    ('Chac’late','Sukar Pasha Ottoman Lounge','Aspire Grand Café','El Cigar Lounge','Kunafa Albisana',
    'le Vesuvio','Lwzaar Seafood Market','Shawarma Albisana','Chaclate','news','events');//list any terms in any taxonomy for which to show link
    
    foreach($taxonomies as $taxonomy) {
    $terms = wp_get_post_terms( $post->ID, $taxonomy );
    foreach($terms as $term) {
    if( in_array( $term->name, $show_link )) $flag=true;
    }
    }
    
    if('Red Velvet Cupcakery'==$term->name) echo 'Go!';
    if('Sukar Pasha Ottoman Lounge'==$term->name) echo 'Go!';
    														if('Aspire Grand Café'==$term->name) echo 'Go!';
    
    if('El Cigar Lounge'==$term->name) echo 'Go!';
    
    if('Kunafa Albisana'==$term->name) echo 'Go!';
    
    if('le Vesuvio'==$term->name) echo 'Go!';
    
    if('Lwzaar Seafood Market'==$term->name) echo 'Go!';
    
    if('Shawarma Albisana'==$term->name) echo 'Go!';
    
    if('Chaclate'==$term->name) echo 'Go!';
    
    if('news'==$term->name) echo 'Go!';
    
    if('events'==$term->name) echo 'Go!';
    
    ?>
    
    
    

    please visit my site dummy link
    http://www.digitalevolutions.ae/akh

    -[This is personal, I would like to find you in social]-

    Shihab

    Moderator bcworkz

    (@bcworkz)

    Hi Shihab,

    Sorry for the delayed response, my internet access last week was more restricted than I imagined. The situation is improving now.

    The problem with your code is you are not using the value of $flag to determine output. Your use of $term->name outside of the loops means that variable only has the value of the last term in the loops, not each term in turn. There’s several possible approaches, it appears you will eventually replace echo 'Go!'; with an actual link output? In which case, you could modify the $show_link in_array() test as follows:

    if( in_array( $term->name, $show_link )) {
       //replace the following with script to output link html
       echo 'Go!';
    }

    You do not need the subsequent series of if() statements for each term, the above code achieves the same purpose more compactly. Also, unless you actually have a term called 'ALL', I do not think using such an argument will return the results you expect. Unless you have confirmed the contrary, I believe you must provide an empty array and the operator ‘NOT_IN’:

    array('taxonomy' => 'brands',
       'terms' => array(),
       'field' => 'slug',
       'operator' => 'NOT_IN'
    ),

    I appreciate the link, but it is not very useful to me unless you explain what is wrong with it and what you want to happen. I hope the above scripts get you closer to a solution.

    -[I’m afraid you will not find me in social media, I do not use it. If you wish to discuss WordPress off forum, I must refuse. I prefer to share my advice openly on this forum so that others may benefit. Private communication defeats this benefit to others. I am open to non-WordPress communication, but it must be via email. I use gmail, my username is nearly the same there, except you must replace the final ‘z’ with an ‘s’ to reach me that way.]-

    -bc (Glenn)

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how link multiple custom taxonomy posts to specified page’ is closed to new replies.