You get the exact unchanged value with:
$event_id = filter_input( INPUT_GET, 'event_post_id', FILTER_VALIDATE_INT );
Here I added the validation filter directly, but you can even move that to separate code for more complex cases.
WordPress’ query variable handling is for cases in which you want to allow changes to the values before they reach your code.
“Best practice” is quite a loaded expression, that’s why we often shy away from that label. 🙂
Write code you and someone else (=future you) can maintain and understand.
If there is a fast and readable PHP way, use that. filter_input()
gives you the variable as sent by the client, and no matter what WP does, it will always stay the same. The super globals $_GET
, $_POST
and so on are writable, you can’t trust them.
Related Posts:
- Difference Between Filter and Action Hooks?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How do I Make a Theme “plugin-ready”?
- How to modify post content before writing to database?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- Hook for post permalink update
- Dynamically Override Fancy Title
- Define a function outside a class and call the function using action or filter hook
- Synchronize Custom post type tags to WordPress default posts tags
- Woocommerce – Hide a Column in Cart Table
- WordPress after content Hook & external template part
- Namespaced action and filter tags
- get_current_screen() return null
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- WordPress custom taxonomy check box to dropdown
- How to get all queries’s results after they have executed?
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Configure WordPress to Generate Scheme-less Relative URLs
- How to find list of all functions bind to a particular hook from my plugin?
- apply_filters() and call_user_func() to define and call a function outside a class
- Limit get_next_post to posts from the same author
- Any way, hook to add content right before the “read more” link?
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Add_action not calling callback function
- How do I replace title with my plugin?
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?
- Which hook should be used to add an action containing a redirect?
- Using query_vars filter
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- Edit plugin without hooks in functions.php
- What’s the earliest point I can get the queried object ID?
- WordPress scheduled task is called but not executed
- Actions or filters fired when data is saved in a custom table
- Display only certain posts based on visitor’s country?
- Conditional add_filter?
- Plugin development, hooks, generate content
- Calling apply_filters on non-documented hooks
- Hook event for upload image in the menu
- Help with callback using do_action_ref_array
- How to allow Unfiltered HTML in a wordpress multisite install
- Is there a way to verified if an add_filter is already applied?
- Determine plugin name from within plugin_action_links filter
- Best Practices for Creating and Handling Forms with Plugins?
- Is there a better way to implement responsive images than what WordPress uses by default?
- multiple functions with same filter
- add_filter : Passing an array instead of the callback function?
- Why is my javascript not invoked in my hooks except wp_head?
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- WordPress is automatically linking plain text email addresses
- How to use a hook to override an update_post_meta call in a plugin?
- External Authentication, session_tokens not destroyed on logout
- correct way to call javascript into hook function
- Why doesn’t my simple the_title filter get applied?
- How to filter the_content() & include content from template
- Get Time Taken By Each Action Hook in WordPress
- Search and Filter
- Force HTTPS 301 redirect with hook
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Plugin uninstall function is not working
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- Gravity Forms Anchor only on Front Page?
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Restrict certain actions to plugin-specific admin menu pages only
- How do i remove the title from a specific page
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- Add hook after content without formatting
- How to enhance a self developed plugin by its own plugin architecture
- How to update global variables in plugin activation callback?
- `registration_errors` filter doesn’t seem to be called
- How to grab data after wp user search is complete
- Override woocommerce loop-start.php from theme using plugin?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Hook for validating and rejecting frontend image upload
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Nested Hooks with do_action for performance reasons – safe/necessary?
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Change Front page displays settings conditionally when user is online
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- plugin modal/popup integration best practice
- WordPress permalink setting
- Get user logged in status from within a plugin. $current_user not defined
- append code after the_content not working
- Send Webhook when post-status is publish or trash
- Using “add_image_size” to register custom image sizes inside plugins not working
- get_term_by() returning null on plugin
- wp_head is not fired from the hook I have used in my plugin
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]