WordPress.org

Ready to get started?Download WordPress

Forums

How can I use "post__not_in" with pre_get_posts? (1 post)

  1. netvision
    Member
    Posted 1 year ago #

    Hello, I checked many examples but couldn't get this working.
    Here is the code I'm using:

    function exclude_some_posts( $query ) {
    	if ( $query->is_main_query() ) {
    	   $query->set('post__not_in', array(1));
    	}}
    add_action( 'pre_get_posts', 'exclude_some_posts' );

Topic Closed

This topic has been closed to new replies.

About this Topic