Tuesday, July 5, 2022
HomeWordPress Developmentwp question - Exception for excluding beforehand displayed posts in queries

wp question – Exception for excluding beforehand displayed posts in queries


I’ve a snippet operating in a theme to exclude beforehand displayed posts when there are a number of queries on a web page. I’m utilizing primarily the brand new WP question blocks to show posts from completely different classes, each on the homepage and on different pages.

That is what I am utilizing:

//Exclude beforehand displayed posts
add_action( 'init', operate() {

    international $displayed_posts;

    $my_displayed_posts = array();

    add_action( 'the_title', operate($title) {
        international $my_displayed_posts;
        $my_displayed_posts[] = get_the_ID();
        return $title;
    } );

    add_filter( 'pre_get_posts', operate($question) {
        international $my_displayed_posts;
        $query->set( 'post__not_in', $my_displayed_posts );
    } );

} );

Nonetheless, there’s one place I’m displaying a customized question and I need to have the ability to present posts that have been proven elsewhere on the web page.

Is there a approach to exclude my customized question from the above code? Or is there one thing I can add to my customized question to disregard the filter?

Clearly it was a wild guess, however I attempted including 'post__in' => $my_displayed_posts, to the question to see if it could work and provides me a spot to start out (after all if that did work, it could require beforehand displayed posts) however it did not change something anyway.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments