I am quite new to WordPress theme development and I have a strange behavior with this custom theme on which I am working: http://lnx.asper-eritrea.com/

As you can see in the home page I have 2 areas for the news:

  1. The first one is titled as IN EVIDENZA for the featured posts.

  2. The second one is titled as ULTIME NOTIZIE for the latest published posts.

So this is the code inside the index.php file that show these 2 news sections:


<header class="header-sezione">
    <h1>ULTIME NOTIZIE:</h1>

        if (have_posts()) :
            // Start the Loop.
            while (have_posts()) : the_post();

                 * Include the post format-specific template for the content. If you want to
                 * use this in a child theme, then include a file called called content-___.php
                 * (where ___ is the post format) and that will be used instead.
                get_template_part('content', get_post_format());

        else :
            // If no content, include the "No posts found" template.
            get_template_part('content', 'none');





<section id="partnerSlide">
    <header class="header-sezione">
        <h2>Partner e Sostenitori</h2>

    <div class="row">
        // 'My_Widgtet_Area' area, where the id is called:
        if (is_active_sidebar('partner-slide')) : ?>

        <div id="widget-sidebar">
                <?php dynamic_sidebar('partner-slide'); ?>
        </div><!-- #widget-sidebar .widget-area -->

        <?php endif; ?>

Then into the functions.php file I created this function to exlude all the posts having featured as tag so that these posts are not shown into the latest posts section:

function get_tag_ID($tag_name) {
    $tag = get_term_by('name', $tag_name, 'post_tag');
    if ($tag) {
        return $tag->term_id;
    } else {
        return 0;

function exclude_featured_tag( $query ) {

    $tagId = get_tag_ID("featured");
    //$tagId = get_tag_ID("evidenza");

    //echo("Featured Tag Id: + $tagId");

    $legacyCategoryId =  get_cat_ID("LegacyPosts");
    //echo("legacy category Id:  + $legacyCategoryId");

    if ( $query->is_home() && $query->is_main_query() ) {

        $query->set( 'tag__not_in', array($tagId));
        $query->set( 'category__not_in',  array($legacyCategoryId));

add_action( 'pre_get_posts', 'exclude_featured_tag' );

This seems work well in all cases except the case in which I have a single published post that have the featured tag.

In this case, as you can see the previous link, happen that the post is shown in booth the section (featured tag and latest tag).

If I a single post and this have also the featured tag it is not excluded from the latest tag.

Why? What am I missing? How can I fix this issue?


  • Actually at where you want to display the single featured post?? it is also the latest post and also featured. or you don't want to publish posts that are both featured and latest ? – Zammuuz Sep 15 '14 at 12:27
  • @barbieegal I created the exclude_featured_tag() function inside functions.php file precisely for exclude the post having the featured tag from the latest post section. It work when I have more than one post (for exampe, if I have one featured post and 2 post that don't have the featured tag the featured tag section show the post with the featured tag and the latest post section show the other posts but not the post having the "featured" tag) This problem happen only when I have a single post and this post have the featured tag – AndreaNobili Sep 15 '14 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.