I see two issues in your code.
First, you pass what could be a string into post__not_in
, which accepts an array of posts IDs (that’s fine if your option holds an array of IDs, but always good to verify).
Second, you seem to be repeating the same thing twice: you modify the query with pre_get_posts
hook, and then you do it again by passing something into query_posts
. In the documentation (this page, the posts_per_page
part), they demonstrate the two techniques as alternatives of doing the same thing.
Related Posts:
- Store sticky post’s ids in a transient
- Custom query for custom post type not getting correct post ID
- Pull posts from all categories if quantity is not met?
- Fetching $_POST from Page Template into functions.php
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- Wp get all the sub pages of the parent using wp query
- why ignore_sticky_posts in sticky post query
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- Using OR conditions in meta_query for query_posts argument
- Query Posts in a Predefined Order
- Order posts by ID in the given order
- Sticky Posts & Posts Per Page [closed]
- Query Multiple Post types each with own meta query
- Get posts by menu ID
- Get the number of posts from the current page results
- ajax category filter
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- WordPress Custom Query to show posts from last x years
- Build a content and excerpt grid loop with paging and options for # of posts
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- Get posts by meta data OR title
- Pagination custom query
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- get query’s query string
- Order by two meta keys
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- Display Posts by modifying the where clause only for my query
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Function to check if author has posted within the last x days
- How do I create my own nested meta_query using posts_where / posts_join?
- wp_query for the first sticky, then display the rest of the posts excluding the first sticky
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Best practice for multiple queries on page
- Shortcode returns escaped HTML tags
- How to Get All Posts but the Private ones?
- Calling a custom excerpt function in a local loop
- All sticky posts are returned in custom query
- How to get any tag ID
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to find out what “Blog pages show at most” is set to [duplicate]
- Get posts using WP_Query
- Multiple search queries on one page
- Finding post content that begins with a specific character
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Pass the same object to multiple widgets in a template with one query
- Retrieve or Query Pages by ID
- Include Sticky Posts in Page Post Count for custom query
- Query sticky posts with thumbnails
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- How do you query wordpress posts using a math formula between multiple meta field values?
- Best practice custom function, where to echo the variables?
- How to get user_id from wordpress database inside ajax function?
- How add a custom posttype name using ACF field to a query post array
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- Hiding posts in a list from specified categories
- Sticky Post default functionality with WP_Query is ignored when using AJAX
- Page navigation doesn’t show when query category
- Multiple instances of Featured Image Query
- Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?
- How can I pick a single post from the latest 3?
- 2 loops on page – one with orderby rand second orderby date
- How do you Query posts with nothing in common?
- Query post with meta_query where date is not in future
- posts_per_page not working
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Next/Prev posts on same page
- Custom category search box for WordPress
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Exclude admin from WP_Query Contributors
- Query with custom taxonomy not working
- Multiple Loops Inside a Function
- Query posts by specific word on title
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP_Query last five posts, simply ordered by meta_value
- Query with a meta value inside a given range
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- How to delete taxonomy term when a wordpress user is removed?
- Exclude category for main query and custom
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- Five posts from a category in footer
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- Change query_posts to WP_Query in page but does not work
- Display posts from only one post form in custom query and exclude in main query
- Multiple loops without repeating content
- Show Sticky Post at the top but do not show again in the loop?
- WP_Query condition affects posts_per_page count