WordPress.org

Ready to get started?Download WordPress

Forums

Related Articles (Exclude certain tags) PROBLEM (1 post)

  1. nicky@3dmg.co.uk
    Member
    Posted 11 months ago #

    Hi, I am trying to exclude certain tags from deciding what related articles will display. Please help if I haven't provided enough info please say what else you need. The code below is from single.php which edits the posts.

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach ($posttags as $tag) {
    $thetags = $thetags . $tag->name . ',';
    }
    }
    query_posts('posts_per_page=6&tag=' . str_replace(" ", "-", $thetags));
    ?>
    <?php if (have_posts() && $posttags != "") { ?>
    <div id="related">
    <h2>Related Articles</h2>
    <?php

    $args = array(
    'post_type' => 'post',
    'tax_query' => array(
    'relation' => 'AND',
    array(
    'taxonomy' => 'post_tag',
    'field' => 'id',
    'terms' => $tagIDs
    ),
    array(
    'taxonomy' => 'post_tag',
    'field' => 'id',
    'terms' => array( 3384, 3708, 3879, 86, 3196, 4163, 4021, 3760, 3696 ),
    'operator' => 'NOT IN'
    )
    )
    );
    $query = new WP_Query( $args );

    while (have_posts()) : the_post();
    if ($currentpost != get_the_title()) {
    ?>
    <p style="clear:both;">" rel="bookmark"><?php the_title(); ?></p>
    <?php
    }
    endwhile; // End the loop. Whew.
    }
    ?>

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 11 months ago by nicky@3dmg.co.uk
  • This topic is not resolved
  • WordPress version: 3.6.1