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 to use WP_query(), query_posts() and pre_get_posts
- why ignore_sticky_posts in sticky post query
- WP Query where title begins with a specific letter
- Query Posts in a Predefined Order
- Sticky Posts & Posts Per Page [closed]
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- get query’s query string
- Order by two meta keys
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Calling a custom excerpt function in a local loop
- All sticky posts are returned in custom query
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- 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
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Sticky Post default functionality with WP_Query is ignored when using AJAX
- Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?
- Next/Prev posts on same page
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Change query_posts to WP_Query in page but does not work
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- Serve specific “template” page at any URL that ends in its slug
- new WP_Query(), have_posts() return false in user_register hook
- How to filter, restrict and return posts based on custom user meta information
- WP Query using tax_query & meta_query
- Slow page loads due to WordPress Core Query
- how to make members list directory through wordpress post custom meta key.
- Add class to first post in custom loop using post_class filter
- Some doubts about how the main query and the custom query works in this custom theme?
- Query Page Content From Theme Options?
- Query all posts if multiple meta key don’t exist
- how to access query string in wordpress?
- How to get all post except particular category without breaking the paging
- How do I rewrite this loop as a new WP_Query style-loop?
- Include current post into loop
- Merge two search functions for custom post type
- Filter Custom Taxonomy Posts
- Make a SQL query with wpdb in WordPress
- How to provide meta_key array to wp_query?
- Filter post query to only show direct children of category
- Order post type by sum of two custom fields
- Query_posts works when appending via AJAX call wp_query doesn’t?
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Exclude authors IDs from WP_Query
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- Posts Query | Query to only show sub categories
- How do I add a relation parameter to my filter query?
- How do I fit WP_Query arguments into a function?
- Show single posts date, in a page of posts
- relation OR instead of AND – Filtered term ID’s in loop
- specific post is not excluded from the loop
- Paginate pages with dynamic query
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- WP_Query Class custom field parameters
- Add AJAX “Load more” on custom query block
- Elementor posts custom query based on tag [closed]
- Facing problem with tax_query results
- Get posts that match defined arrays of tags
- how to move a page from one drop down menu to another drop down menu
- trying to change from query_post to WP_Query
- How to query most recent post for each author?
- I need query_posts() to order results first by a meta value and then by post ID
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to search CPTs in draft using get_page_by_title()
- How to show post title in content editor in backend?
- why ignore_sticky_posts in sticky post query
- Orderby query does not work for custom fields even with meta query
- Custom WP_query and integrating into theme file
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Query_post 5 post first / last of post_id
- WP_Query causing links to not work
- ordering and optimizing functions
- How to organize a WP_Query’s list of posts by category and display category title?
- query post based on comparison
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- custom query to get posts
- Multiple loop for “featured” items returns wrong posts
- Query Posts to fetch Posts with Unique Tag
- query_posts problem – need help
- Integrating custom API for post content into Admin interface & Public Website [closed]
- WP_Query and DES sort for Custom Taxonomy based upon a meta field?
- How to write a query-function as a query-shortcode?
- First post outside of loop, homepage only?
- Show number of posts AND number on current page (cannot make it work)
- Why ignore_sticky_posts argument is in sticky post query?
- Excluding a category from frontpage but not from WP_Query