The init
hook runs well before pre_get_posts
so dumping the query at that point– on init
— isn’t going to reflect anything that will be done much later. I don’t think there is anything wrong with your code, you misunderstand the sequence of actions. What you expect to happen isn’t what actually happens.
Related Posts:
- Scheduled event does not run at midnight
- pre_get_post alter current post id
- Setting post_id for single.php based on URL without a redirect
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- Plugin Form Submission Best Practice
- WP 3.3 How to Add Menu Items to the Admin Bar?
- Unit tests – Dealing with dependencies
- Changing Plugin Load Order
- Should I create a theme or a plugin?
- How should you hook a session_start() when authoring a plugin?
- How to sync with plugins update after I have done manual optimizations?
- How to retrieve a value via get_option when the option_value is stored in a multi-dimensional array?
- How to change wordpress post title?
- Add Admin Menu Inside Construct or Init
- How to create a plugin that only operates on the home page?
- How to properly load text domain of custom mu plugin
- How to add multiple copies of a widget from “available widgets”
- How to add quick edit and bulk edit fields to users admin section
- How do I approach removing menu items on the fly based on settings in my plugin?
- Can I use core’s “or Link to Existing Content” feature in my plugin?
- Plugin with specific admin menu icon
- What does $_registered_pages do?
- How do I change the initial quantity of a product in woocommerce?
- Redirect traffic to plugin
- How to Download and install plugin database remotely
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- using new WP_Query in save_post function alters $post
- Preview Changes button missing on custom post type page since updating to 3.4
- Show special field when correct shipping is chosen
- Custom Taxonomy to dropdown box on adminside wordpress
- WP_Editor – Saving Value into Plugin Option – Stripping HTML
- On cliking add new post redirect user to a custom page first
- How To Consistently Enforce Rewrite Rule in Plugin Development
- Warning: Cannot modify header information – How to resolve this issue? [closed]
- $paged always 0 on plugin’s custom page
- Create a new post using rest api and save featured image using an external image url
- How to restrict access to image folder depending on whether product is purchased or not?
- Caching the_content calls
- Is there a way in which I can compare product id with the order id to display content on front end before placing the order? [closed]
- Video Security just like facebook [closed]
- Link Pop-up in custom plugin
- How to handle shortcodes through plugin
- Run a function when new image is uploaded in media library
- Setting up Version Control for WordPress plugin development
- Ajax submit result opens in admin-ajax.php
- WordPress debug messages not displaying
- Show message from backend
- get author of published post
- Error passing post_content to function
- PHP File_exist() not working – Checking if File Exist in WordPress Theme Directory
- Woocommerce inventory [closed]
- Add a check box in Menu Settings
- How to register my code as a plugin
- Is there any way to fire heartbeat API from for website visitors?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Cannot stop wpautop from messing up my plug-in output
- How can I prevent ‘500 internal server error’ because of a long install process?
- Update product prices from remote file
- Displaying custom content from a plugin within the active theme
- Using wp_mail to send email?
- Which wp plugin can use Create, Edit and Delete Email address from WordPress Dashboard
- product-attribute-slug-is-too-long-28-characters-max
- Custom plugin & calling REST api of wordpress instance the plugins is running on
- Add variables from rewrite rules to query var
- Show list of categories that has posts with different taxonomies
- “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
- How do I specify where to save the debug.log?
- How do I ensure I can loop through every enqueued script and CSS?
- What is the source of the $post_id in a hook argument?
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- Plugins Settings page not updating
- Code for cron to delete posts that contain specific expression (e.g. “unable to fetch” every 30 minutes
- My enqueue admin style function doesn’t work because of ?=ver
- Use content filter on the post that is password-protected
- foreach argument to get specific file types getting too many returns
- How to fetch the post content from the wordpress editor before it can be saved(published)?
- pull data from wordpress database
- How does one set cookies in WordPress without getting the ‘headers not sent’ error? within WP
- Filter the_content() to add custom figure tags
- Glyphicons Dont Show in WordPress Plugin Only
- Return all roles, including custom roles
- Change the search results header from plugin
- Mapping multiple URLs to same page
- Installing plugins on installation/activation
- Add query string variables to all hyperlinks URL matching a specified domain
- Virtual Page with Registration form
- Is there such a thing as a WordPress console?
- Loading jQuery library from WordPress admin
- Build a dynamic block using the default attributes
- How to display .ptm file in my WP site without JAVA
- Show Admin Menu
- How to replace content of a block in and re-render on change?
- extending a core block doesn’t work inside the editor
- register_activation_hook doesn’t execute without add_action(‘init’,’some-function’)
- Getting similar posts by custom field value
- Does WP REST API cache internally executed (rest_do_request) requests?
- Trouble Importing whatsapp-web.js in a WordPress Plugin Development
- ‘useSate’ error when using React on the frontend in custom block plugin