• AdrianPB

    (@adrianpb)


    So this’ll be a little complex. We have a Featured section, where we place the most important posts. This section works as follows: We have the single.php, in which every single post shows, now just below the single post, the featured section begins.

    It shows all the features posts with the same format as the single post, but whenever the single post is a featured one, it appears twice instead of once, because it’s the single post and aside from that, it’s a featured post.

    Is there a way that I can filter that? So if one featured post is the same as the single post it won’t be displayed?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    assuming your used code is based on a custom WP_Query, try to use the ‘post__not_in’ parameter;

    http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Post_.26_Page_Parameters

    We have the single.php, in which every single post shows, now just below the single post, the featured section begins.

    is all the code in single.php or are you using a plugin?

    what theme are you working with?

    Thread Starter AdrianPB

    (@adrianpb)

    Briefed theme, and it’s all on code, want the code?
    ANd by using ‘post__not_in’ how do I get the parent’s slug for instance, to filter it?

    I’m pretty new to php, here’s the query that I’m currently using in the featured loop.

    $postpromo = new WP_Query( array('post_type' => array( 'post', 'homepage_slider', 'portfolio', 'reportajes_slider' ), 'posts_per_page' => 6, 'meta_key' => 'promovido', 'orderby' => 'date', 'order' => 'DESC' ) ); ?>

    It’s in spanish, basically “promovido” is a custom field that determines if a post should be featured or not, and this is a loop for all my custom post types (portfolio, post, homepage_slider and reportajes_slider”

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to filter a post in a loop?’ is closed to new replies.